-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathrekognitionTest.py
57 lines (38 loc) · 1.04 KB
/
rekognitionTest.py
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
"""
import boto3
if __name__ == "__main__":
fileName='Good WinLoss.png'
bucket='trash-cam'
client=boto3.client('rekognition')
response = client.detect_labels(Image={'S3Object':{'Bucket':bucket,'Name':fileName}},MinConfidence=75)
print('Detected labels for ' + fileName)
print(response)
for label in response['Labels']:
print (label['Name'] + ' : ' + str(label['Confidence']))
"""
import boto3
BUCKET = "trash-cam"
KEY = "toProcess.jpg"
def detect_labels(bucket, key, max_labels=10, min_confidence=90, region="us-east-1"):
rekognition = boto3.client("rekognition", region)
response = rekognition.detect_labels(
Image={
"S3Object": {
"Bucket": bucket,
"Name": key,
}
},
MaxLabels=max_labels,
MinConfidence=min_confidence,
)
return response['Labels']
for label in detect_labels(BUCKET, KEY):
print ("{Name} - {Confidence}".format(**label))
"""
Expected output:
People - 99.2436447144%
Person - 99.2436447144%
Human - 99.2351226807%
Clothing - 96.7797698975%
Suit - 96.7797698975%
"""