How to convert an image of text into a binary view in Salesforce Apex using Deep Learning

Cloudmersive
1 min readJul 11, 2020

--

The process of binarization, or converting an image into pure black and white is a very necessary step in the preprocessing phase of OCR. Without well performed binarization, the optical character recognition will either fail or be reduced in accuracy. However, this conversion is not as simple as you might think, requiring cutting-edge Deep Learning to achieve quality results. Instead of spending a week training an AI, I’m going to show you how to get this done in minutes.

First download this file and extract the client folder into your Apex project.

https://github.com/Cloudmersive/Cloudmersive.APIClient.Apex.OCR/archive/master.zip

Now we are going to go ahead and call preprocessingBinarizeAdvanced, like we see down here:

SwagPreprocessingApi api = new SwagPreprocessingApi();SwagClient client = api.getClient();// Configure API key authorization: ApikeyApiKeyAuth Apikey = (ApiKeyAuth) client.getAuthentication('Apikey');Apikey.setApiKey('YOUR API KEY');Map<String, Object> params = new Map<String, Object>{'imageFile' => Blob.valueOf('Sample text file\nContents')};try {// cross your fingersBlob result = api.preprocessingBinarizeAdvanced(params);System.debug(result);} catch (Swagger.ApiException e) {// ...handle your exceptions}

Done.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

No responses yet