Sign inSign up

ricardosouzamorais/abbyy-ocr-process

By ricardosouzamorais

•Updated over 7 years ago

Image
0

591

ricardosouzamorais/abbyy-ocr-process repository overview

⁠Purpose

This is an image for processing files with ABBYY Cloud OCR, using Python 3.7, based on Quick start with OCR SDK for Python⁠.

This is not an asynchronous code, so it hangs a little bit waiting a return from the ABBY Cloud.

IMPORTANT: The are a bunch of API methods available but this code takes care only of processImage⁠ method and processTextField⁠.

⁠Before Starting

First of all you need an account at ABBY Cloud OCR SDK⁠ and also an application configured for your submission.
After creating your account, create an application and save its name. A password will be sent to you through mail.

⁠Running the Image

⁠Environment Variables

On your environment, code below is for Linux, export three important variables as follows:

  • ABBYY_SERVER_URL - URL of the ABBYY OCR Server where you have registered you account.
  • ABBYY_APPID - The application ID that you registered.
  • ABBYY_PWD - The application password that was sent to you by ABBYY.
export ABBYY_SERVER_URL="https://cloud-westus.ocrsdk.com"
export ABBYY_APPID="<YOUR_APPLICATION_ID>"
export ABBYY_PWD="<YOUR_APPLICATION_PASSWORD>"

⁠Image Command Arguments

There are optional arguments that can be sent with shortcut letters, as follows:

Optional ArgumentDescription
-l
or
--language
Specifies the recognition language. Default: English
Supported languages⁠

The following arguments represent a mutual exclusive group and just one of them can be used, and in fact, must be used for choosing which API method should be used: processImage or processTextField

Optional ArgumentDescription
-image
This is DEFAULT.
Specifies the operation as image which calls the processImage⁠ API method.
-textFieldSpecifies the operation as textField which calls the processTextField⁠ API method.
⁠processImage - Optional Arguments

The following arguments represent a mutual exclusive group and just one of them can be used, and in fact, must be used for processing the OCR request through processImage API method.

Optional ArgumentDescription
-txt

This is DEFAULT.
The recognized text is exported to the file line by line from left to right. E.g. if the text was originally put in columns, the first lines of every column will be saved, then the second lines, etc.
Please take into account the fact that in this format only text will be saved. No images or barcodes will remain in the output file. If you want to save the barcode recognition results in the exported file, use the txtUnstructured format.
-txtUnstructuredThe exported file contains the text that was saved according to the order of the original blocks.
-rtfExports the result into RTF format.
-docxExports the result into DOCX format.
-xlsxExports the result into XLSX format.
-pptxExports the result into PPTX format.
-pdfSearchableThe entire image is saved as a picture, the recognized text is put under it.
-pdfaThe file is saved in the PDF/A-1b format, with the entire image saved as a picture, and recognized text put under it.
-pdfTextAndImagesThe recognized text is saved as text, and the pictures are saved as pictures.
-xmlExports the result into XML format.
-xmlForCorrectedImageThe same as xml, but all coordinates written into the output XML file relate to the corrected image, not the original.
⁠processTextField - Optional Arguments

The following arguments represent a mutual exclusive group and just one of them can be used, and in fact, must be used for processing the OCR request through processTextField API method.

Optional ArgumentDescription
-allTextTypes
This is DEFAULT.
Specifies text type⁠ as normal,typewriter,matrix,index,ocrA,ocrB,e13b,cmc7,gothic to be used by processTextField API method.
-normalSpecifies text type⁠ as normal to be used by processTextField API method.
-typewriterSpecifies text type⁠ as typewriter to be used by processTextField API method.
-matrixSpecifies text type⁠ as matrix to be used by processTextField API method.
-indexSpecifies text type⁠ as index to be used by processTextField API method.
-ocrASpecifies text type⁠ as ocrA to be used by processTextField API method.
-ocrBSpecifies text type⁠ as ocrB to be used by processTextField API method.
-e13bSpecifies text type⁠ as e13b to be used by processTextField API method.
-cmc7Specifies text type⁠ as cmc7 to be used by processTextField API method.
-gothicSpecifies text type⁠ as gothic to be used by processTextField API method.

⁠Examples

You must have set your environment variables before starting the container.

⁠processImage API with output as XSLX

The following example, code below is for Linux, submits all files inside input folder, of host that is mapped to container, and request its return to be a XLSX using Brazilian Portuguese as the recognition language.

Run the following:

docker run -e ABBYY_SERVER_URL="$ABBYY_SERVER_URL" \
            -e ABBYY_APPID="$ABBYY_APPID" \
            -e ABBYY_PWD="$ABBYY_PWD" \
            -v $(pwd)/input:/usr/app/input \
            -v $(pwd)/output:/usr/app/output \
            ricardosouzamorais/abbyy-ocr-process \
            -l "PortugueseBrazilian" -xlsx
⁠processTextField API

The following example, code below is for Linux, submits all files inside input folder, of host that is mapped to container, and request its return to be an XML (only available output format for this API method) using Brazilian Portuguese as the recognition language.

Run the following:

docker run -e ABBYY_SERVER_URL="$ABBYY_SERVER_URL" \
            -e ABBYY_APPID="$ABBYY_APPID" \
            -e ABBYY_PWD="$ABBYY_PWD" \
            -v $(pwd)/input:/usr/app/input \
            -v $(pwd)/output:/usr/app/output \
            ricardosouzamorais/abbyy-ocr-process \
            -l "PortugueseBrazilian" -textField

Tag summary

Content type

Image

Digest

Size

354.4 MB

Last updated

over 7 years ago

docker pull ricardosouzamorais/abbyy-ocr-process