Last active
September 22, 2018 17:15
-
-
Save hariby/8076766025f4fde2772d518a8198a26b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import io, boto3 | |
import numpy as np | |
from PIL import Image | |
from botocore.exceptions import ClientError | |
REGION = 'us-east-2' | |
CollectionId = '<CollectionID>' | |
def get_name(frame): | |
rekognition = boto3.client('rekognition', region_name=REGION) | |
image = Image.fromarray(np.uint8(frame[:,:,::-1])) | |
stream = io.BytesIO() | |
image.save(stream,format="JPEG") | |
image_binary = stream.getvalue() | |
try: | |
response = rekognition.search_faces_by_image( | |
CollectionId=CollectionId, | |
Image={'Bytes':image_binary} | |
) | |
return response['FaceMatches'][0]['Face']['FaceId'] | |
except ClientError as err: | |
code = err.response['Error']['Code'] | |
if code == 'InvalidParameterException': | |
return 'NOFACE' | |
elif code == 'AccessDeniedException': | |
return 'DENIED' | |
elif code == 'InvalidImageFormatException': | |
return 'ILLFORMED' | |
else: | |
return 'ERR' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment