Skip to content

Instantly share code, notes, and snippets.

@vittorio-nardone
Created January 17, 2020 09:27
Show Gist options
  • Save vittorio-nardone/49f6c5fa2ef4841293afc9426079f1bc to your computer and use it in GitHub Desktop.
Save vittorio-nardone/49f6c5fa2ef4841293afc9426079f1bc to your computer and use it in GitHub Desktop.
Text detection in Python and AWS Rekognition
def detect_text(photo, bucket):
"""Detect text in an image hosted as bucket object
:param phone: Object name
:param bucket: Bucket name
:return:
"""
client=boto3.client('rekognition')
response=client.detect_text(Image={'S3Object':{'Bucket':bucket,'Name':photo}})
textDetections=response['TextDetections']
print ('Detected text\n----------')
for text in textDetections:
if 'ParentId' in text:
continue
print ('Detected text:' + text['DetectedText'])
print ('Confidence: ' + "{:.2f}".format(text['Confidence']) + "%")
print ('Id: {}'.format(text['Id']))
print ('Type:' + text['Type'])
print()
return response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment