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.
- Tesseract-OCR
- Tesseract pre-compiled binaries for Amazon Linux 1 and Windows are included in this repo.
- 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.
Local testing is supported only for Windows.
Modify /test_suite to add test cases.
Execute ocr_tester.py to run tests.
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 |
- Create a ZIP file with the following structure (tested using 7 Zip):
.
├── lambda_handler.py
├── ocr.py
└── dependencies
└── tesseract_ocr_linux
- # for an AWS account.
- Create S3 bucket.
- Upload ZIP file to S3 bucket.
- Create Lambda function.
- Configure Lambda function with the following settings:
Setting | Value |
---|---|
Runtime | Python 3.7 |
Handler | lambda_handler.lambda_handler |
Timeout | 30+ seconds |
- Import source code from S3 bucket ZIP file.
- Ready to use!