AWS Code Sample
Catalog demonstrates how to detect faces in an image loaded from an S3 Bucket.

# Copyright 2010-2019, Inc. or its affiliates. All Rights Reserved. # # This file is licensed under the Apache License, Version 2.0 (the "License"). # You may not use this file except in compliance with the License. A copy of the # License is located at # # # # This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS # OF ANY KIND, either express or implied. See the License for the specific # language governing permissions and limitations under the License. import boto3 import json if __name__ == "__main__": # Change bucket to your S3 bucket that contains the image file. # Change photo to your image file. photo='input.jpg' bucket='bucket' client=boto3.client('rekognition') response = client.detect_faces(Image={'S3Object':{'Bucket':bucket,'Name':photo}},Attributes=['ALL']) print('Detected faces for ' + photo) for faceDetail in response['FaceDetails']: print('The detected face is between ' + str(faceDetail['AgeRange']['Low']) + ' and ' + str(faceDetail['AgeRange']['High']) + ' years old') print('Here are the other attributes:') print(json.dumps(faceDetail, indent=4, sort_keys=True))

Sample Details

Service: rekognition

Last tested: 2019-01-3

Author: reesch (AWS)

Type: full-example

On this page: