-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
72 lines (55 loc) · 2.06 KB
/
main.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import boto3
import boto3.session
import io
from PIL import ImageDraw, ExifTags, ImageColor
import PIL.Image as Image
from IPython.display import display, Image
from collections import defaultdict
import logging
import boto3
from botocore.exceptions import ClientError
import boto3
rekognition = boto3.client('rekognition')
def detect_labels(photo, bucket):
client = boto3.client('rekognition')
response = client.detect_labels(Image={'S3Object': {'Bucket': bucket, 'Name': photo}},
MaxLabels=10)
print('Detected labels for ' + photo)
print()
label_counts = {}
for label in response['Labels']:
name = label['Name']
count = len(label['Instances'])
label_counts[name] = count
print(label_counts)
peopleCount=int(label_counts['Person'])
chairCount=int(label_counts['Chair'])
print('I found ' + str(label_counts['Person']) + ' people.')
print('I found ' + str(label_counts['Chair']) + ' chairs.')
if (chairCount - peopleCount <= 0):
print("All chairs taken.")
else:
print((chairCount - peopleCount), "chairs available.")
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 mainTrain():
photo = 'FinalTestCase6.jpeg'
bucket = 'worchesterbucket'
label_count =detect_labels(photo, bucket)
mainTrain()