-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample_rekognition_items.py
More file actions
33 lines (26 loc) · 919 Bytes
/
Copy pathexample_rekognition_items.py
File metadata and controls
33 lines (26 loc) · 919 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import boto3
import json
rek = boto3.client('rekognition') # Setup the Rekognition Client
s3 = boto3.resource('s3') # Setup the S3 Resource
print "Getting Image"
image = s3.Object('my-amazing-bucket', 'picnic.png') # Get an image to work with
img_data = image.get()['Body'].read() # Read the image
print "Image retrieved"
print "Sending to Rekognition"
# Detect the items in the image
results = rek.detect_labels(
Image={
'Bytes': img_data }
)
print "Rekognition done"
# Print the result
print json.dumps(
results['Labels'],
indent=2
)
# Print a message for each item
for label in results["Labels"]:
print "I am {}% confident of of the image having a {} in it".format(
int(label['Confidence']),
label['Name'],
)