inHow to extract information from a form photo in Java using OCR

  1. Repository
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.github.Cloudmersive</groupId>
<artifactId>Cloudmersive.APIClient.Java</artifactId>
<version>v2.75</version>
</dependency>
</dependencies>
// Import classes://import com.cloudmersive.client.invoker.ApiClient;//import com.cloudmersive.client.invoker.ApiException;//import com.cloudmersive.client.invoker.Configuration;//import com.cloudmersive.client.invoker.auth.*;//import com.cloudmersive.client.ImageOcrApi;ApiClient defaultClient = Configuration.getDefaultApiClient();// Configure API key authorization: ApikeyApiKeyAuth Apikey = (ApiKeyAuth) defaultClient.getAuthentication("Apikey");Apikey.setApiKey("YOUR API KEY");// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)//Apikey.setApiKeyPrefix("Token");ImageOcrApi apiInstance = new ImageOcrApi();File imageFile = new File("/path/to/file"); // File | Image file to perform OCR on.  Common file formats such as PNG, JPEG are supported.Object formTemplateDefinition = null; // Object | Form field definitionsString recognitionMode = "recognitionMode_example"; // String | Optional, enable advanced recognition mode by specifying 'Advanced', enable handwriting recognition by specifying 'EnableHandwriting'.  Default is disabled.String preprocessing = "preprocessing_example"; // String | Optional, preprocessing mode, default is 'Auto'.  Possible values are None (no preprocessing of the image), and Auto (automatic image enhancement of the image - including automatic unrotation of the image - before OCR is applied; this is recommended).  Set this to 'None' if you do not want to use automatic image unrotation and enhancement.String diagnostics = "diagnostics_example"; // String | Optional, diagnostics mode, default is 'false'.  Possible values are 'true' (will set DiagnosticImage to a diagnostic PNG image in the result), and 'false' (no diagnostics are enabled; this is recommended for best performance).String language = "language_example"; // String | Optional, language of the input document, default is English (ENG).  Possible values are ENG (English), ARA (Arabic), ZHO (Chinese - Simplified), ZHO-HANT (Chinese - Traditional), ASM (Assamese), AFR (Afrikaans), AMH (Amharic), AZE (Azerbaijani), AZE-CYRL (Azerbaijani - Cyrillic), BEL (Belarusian), BEN (Bengali), BOD (Tibetan), BOS (Bosnian), BUL (Bulgarian), CAT (Catalan; Valencian), CEB (Cebuano), CES (Czech), CHR (Cherokee), CYM (Welsh), DAN (Danish), DEU (German), DZO (Dzongkha), ELL (Greek), ENM (Archaic/Middle English), EPO (Esperanto), EST (Estonian), EUS (Basque), FAS (Persian), FIN (Finnish), FRA (French), FRK (Frankish), FRM (Middle-French), GLE (Irish), GLG (Galician), GRC (Ancient Greek), HAT (Hatian), HEB (Hebrew), HIN (Hindi), HRV (Croatian), HUN (Hungarian), IKU (Inuktitut), IND (Indonesian), ISL (Icelandic), ITA (Italian), ITA-OLD (Old - Italian), JAV (Javanese), JPN (Japanese), KAN (Kannada), KAT (Georgian), KAT-OLD (Old-Georgian), KAZ (Kazakh), KHM (Central Khmer), KIR (Kirghiz), KOR (Korean), KUR (Kurdish), LAO (Lao), LAT (Latin), LAV (Latvian), LIT (Lithuanian), MAL (Malayalam), MAR (Marathi), MKD (Macedonian), MLT (Maltese), MSA (Malay), MYA (Burmese), NEP (Nepali), NLD (Dutch), NOR (Norwegian), ORI (Oriya), PAN (Panjabi), POL (Polish), POR (Portuguese), PUS (Pushto), RON (Romanian), RUS (Russian), SAN (Sanskrit), SIN (Sinhala), SLK (Slovak), SLV (Slovenian), SPA (Spanish), SPA-OLD (Old Spanish), SQI (Albanian), SRP (Serbian), SRP-LAT (Latin Serbian), SWA (Swahili), SWE (Swedish), SYR (Syriac), TAM (Tamil), TEL (Telugu), TGK (Tajik), TGL (Tagalog), THA (Thai), TIR (Tigrinya), TUR (Turkish), UIG (Uighur), UKR (Ukrainian), URD (Urdu), UZB (Uzbek), UZB-CYR (Cyrillic Uzbek), VIE (Vietnamese), YID (Yiddish)try {FormRecognitionResult result = apiInstance.imageOcrPhotoRecognizeForm(imageFile, formTemplateDefinition, recognitionMode, preprocessing, diagnostics, language);System.out.println(result);} catch (ApiException e) {System.err.println("Exception when calling ImageOcrApi#imageOcrPhotoRecognizeForm");e.printStackTrace();}
{
"Successful": true,
"FieldValueExtractionResult": [
{
"TargetField": {
"FieldID": "string",
"LeftAnchor": "string",
"TopAnchor": "string",
"BottomAnchor": "string",
"AnchorMode": "string",
"DataType": "string",
"TargetDigitCount": 0,
"MinimumCharacterCount": 0,
"AllowNumericDigits": true,
"VerticalAlignmentType": "string",
"HorizontalAlignmentType": "string",
"TargetFieldWidth_Relative": 0,
"TargetFieldHeight_Relative": 0,
"TargetFieldHorizontalAdjustment": 0,
"TargetFieldVerticalAdjustment": 0,
"Ignore": [
"string"
],
"Options": "string"
},
"FieldValues": [
{
"Text": "string",
"XLeft": 0,
"YTop": 0,
"Width": 0,
"Height": 0,
"BoundingPoints": [
{
"X": 0,
"Y": 0
}
],
"ConfidenceLevel": 0
}
]
}
],
"TableValueExtractionResults": [
{
"TableDefinition": {
"TableID": "string",
"ColumnDefinitions": [
{
"ColumnID": "string",
"TopAnchor": "string",
"AnchorMode": "string",
"DataType": "string",
"MinimumCharacterCount": 0,
"AllowNumericDigits": true
}
],
"TargetTableHeight_Relative": 0,
"TargetRowHeight_Relative": 0
},
"TableRowsResult": [
{
"TableRowCellsResult": [
{
"ColumnID": "string",
"CellValues": [
{
"Text": "string",
"XLeft": 0,
"YTop": 0,
"Width": 0,
"Height": 0,
"BoundingPoints": [
{
"X": 0,
"Y": 0
}
],
"ConfidenceLevel": 0
}
]
}
]
}
]
}
],
"Diagnostics": [
"string"
],
"BestMatchFormSettingName": "string"
}

--

--

--

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

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How to save P3C in Cold Storage with a Paper Wallet

January Recap; Kicking off 2019

HADOOP CLUSTER TASK— Steps to Contributing limited storage as Slave Node to the cluster

Five Productivity Hacks for Coders

Deploying WordPress Application on Kubernetes and AWS using Terraform

MILLER AND BOOTSTRAP SWEEP CIRCUITS.

Facilitating Retrospectives for team bonding and workflow improvement

Partners holding big jigsaw puzzle pieces about to put them together

What’s new in NIMPEE v2.0

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Cloudmersive

Cloudmersive

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

More from Medium

Image Processing API: How to Crop an Image to a Rectangular Area using Java

How to Validate a PowerPoint (PPTX) Presentation using Java

How to Extract, Decompress Files and Folders from a Zip Archive Automatically with Java

Easy Barcode Generation: Create a QR Barcode as a PNG File