-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCode.py
More file actions
43 lines (32 loc) · 1.29 KB
/
Copy pathCode.py
File metadata and controls
43 lines (32 loc) · 1.29 KB
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
34
35
36
37
38
39
40
41
42
43
import boto3
def detect_labels(photo):
bucket = "your_bucket_name"
client=boto3.client('rekognition')
response = client.detect_labels(Image={'S3Object':{'Bucket':'prpr99','Name':photo}},
MaxLabels=10)
print('Detected labels for ' + photo)
print()
for label in response['Labels']:
print ("Label: " + label['Name'])
print ("Confidence: " + str(label['Confidence']))
print ("Instances:")
for instance in label['Instances']:
print (" Bounding box")
print (" Top: " + str(instance['BoundingBox']['Top']))
print (" Left: " + str(instance['BoundingBox']['Left']))
print (" Width: " + str(instance['BoundingBox']['Width']))
print (" Height: " + str(instance['BoundingBox']['Height']))
print (" Confidence: " + str(instance['Confidence']))
print()
print ("Parents:")
for parent in label['Parents']:
print (" " + parent['Name'])
print ("----------")
print ()
return len(response['Labels'])
def main():
photo = input("Enter the name of the photo (including extension): ")
label_count=detect_labels(photo)
print("Labels detected: " + str(label_count))
if __name__ == "__main__":
main()