forked from newsdev/who-the-hill
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rekognitionrecognizer.py
26 lines (23 loc) · 1014 Bytes
/
rekognitionrecognizer.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
import json
import requests
from image import Image
from abstractrecognizer import AbstractRecognizer
class RekognitionRecognizer(AbstractRecognizer):
""" An implementation of the AbstractRecognizer class to work with our Rekognition wrapper server """
def recognize(self, image):
image.get_image_file().seek(0)
r = requests.post(self.recognition_endpoint, files={'file': image.get_image_file().read()})
face_obj = json.loads(r.text)
if ("CelebrityFaces" in face_obj and len(face_obj['CelebrityFaces']) > 0):
celeb_objs = face_obj['CelebrityFaces']
for obj in celeb_objs:
bounding_box = obj['Face']['BoundingBox']
image.add_face(
bounding_box['Left'],
bounding_box['Top'],
bounding_box['Width'],
bounding_box['Height'],
obj['MatchConfidence'],
obj['Name']
)
return image