Deep Learning OCR on Document and Receipt Photos in Apex

Source: Deep Learning on Medium

To begin, we need to download our Apex Client. Then extract the /client folder into your Apex project. With that out of the way, all we need to do is call imageOcrPhotoWordsWithLocation.

SwagImageOcrApi api = new SwagImageOcrApi();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'),'recognitionMode' => 'recognitionMode_example','language' => 'language_example','preprocessing' => 'preprocessing_example','diagnostics' => 'diagnostics_example'};try {// cross your fingersSwagPhotoToWordsWithLocationResult result = api.imageOcrPhotoWordsWithLocation(params);System.debug(result);} catch (Swagger.ApiException e) {// ...handle your exceptions}

The API will proceed to apply some deep learning to the input photograph and provide its results in text form.