Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import boto3
- from io import BytesIO
- from PIL import Image
- if __name__== "__main__":
- session = boto3.Session(region_name="ap-southeast-1")
- rekognition = session.client('rekognition')
- s3 = session.client('s3')
- response = rekognition.detect_faces(
- Image={
- 'S3Object': {
- 'Bucket': 'test-bucket-julo',
- 'Name': '2.jpeg',
- },
- },
- )
- file_byte_string = s3.get_object(Bucket='ml.adindabudi.me', Key='rekognition/samples/2.jpeg')['Body'].read()
- img = Image.open(BytesIO(file_byte_string))
- img_width, img_height = img.size
- left = response['FaceDetails'][0]['BoundingBox']['Left'] * img_width
- top = response['FaceDetails'][0]['BoundingBox']['Top'] * img_height
- width = response['FaceDetails'][0]['BoundingBox']['Width'] * img_width
- height = response['FaceDetails'][0]['BoundingBox']['Height'] * img_height
- cropped = img.crop((left , top , (left + width), (top + height)))
- imgByteArr = BytesIO()
- cropped.save(imgByteArr, format=img.format)
- imgByteArr = imgByteArr.getvalue()
- response = rekognition.index_faces(
- CollectionId='julo',
- Image={
- 'Bytes': imgByteArr,
- },
- QualityFilter='LOW'
- )
- print(response)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement