Skip to content
This repository has been archived by the owner on Jan 28, 2021. It is now read-only.

AWS Lambda function that executes Tesseract-OCR on Base 64 encoded images.

License

Notifications You must be signed in to change notification settings

sethepeterson/tesseract-ocr-lambda-function

Repository files navigation

tesseract-ocr-lambda-function

Python 3.7 Language grade: Python Total alerts License
AWS Lambda function that executes Tesseract (Optimal Character Recognition Engine) on Base 64 encoded images.
The function also implements horizontal whitespace detection through use of Tesseract's TSV output.

Dependencies

  • Tesseract-OCR
  • Windows
    • Required for local testing.
  • Python 3.7.5
    • Required for local testing.
    • The Tesseract Linux binary in this repo is only compatible with Amazon Linux 1, which corresponds to Lambda Python runtimes ≤ Version 3.7.5.

Testing

Local testing is supported only for Windows.
Modify /test_suite to add test cases.
Execute ocr_tester.py to run tests.

Usage

Include a Base 64 encoded image in the function invocation payload.
The function will return a JSON response with the following variables:

  • text - String containing the recognized text or error info.
  • statusCode - Integer representing function success status. See table below:
Result Status Code
Success 200
Invalid Base 64 400
OCR error 500

Deployment

  1. Create a ZIP file with the following structure (tested using 7 Zip):
    .
    ├── lambda_handler.py
    ├── ocr.py
    └── dependencies
        └── tesseract_ocr_linux
  1. Sign up for an AWS account.
  2. Create S3 bucket.
  3. Upload ZIP file to S3 bucket.
  4. Create Lambda function.
  5. Configure Lambda function with the following settings:
Setting Value
Runtime Python 3.7
Handler lambda_handler.lambda_handler
Timeout 30+ seconds
  1. Import source code from S3 bucket ZIP file.
  2. Ready to use!

Releases

No releases published

Packages

No packages published

Languages