-
-
Save Sande3p/843e1c9998154ed5def058ed243fdd7b to your computer and use it in GitHub Desktop.
img-reader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import boto3 | |
import base64 | |
def lambda_handler(event, context): | |
eventBody = json.loads(json.dumps(event))['body'] | |
imageBase64 = json.loads(eventBody)['Image'] | |
# Amazon Textract client | |
textract = boto3.client('textract') | |
# Call Amazon Textract | |
response = textract.detect_document_text( | |
Document={ | |
'Bytes': base64.b64decode(imageBase64) | |
}) | |
detectedText = '' | |
# Print detected text | |
for item in response['Blocks']: | |
if item['BlockType'] == 'LINE': | |
detectedText += item['Text'] + '\n' | |
return { | |
'statusCode': 200, | |
'body': json.dumps(detectedText) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment