Amazon Rekognition

2017/08/24 - Amazon Rekognition - 4 updated api methods

Changes  Update the enum value of LandmarkType and GenderType to be consistent with service response

CompareFaces (updated) Link ¶
Changes (response)
{'FaceMatches': {'Face': {'Landmarks': {'Type': {'eyeLeft',
                                                 'eyeRight',
                                                 'leftEyeBrowLeft',
                                                 'leftEyeBrowRight',
                                                 'leftEyeBrowUp',
                                                 'leftEyeDown',
                                                 'leftEyeLeft',
                                                 'leftEyeRight',
                                                 'leftEyeUp',
                                                 'leftPupil',
                                                 'mouthDown',
                                                 'mouthLeft',
                                                 'mouthRight',
                                                 'mouthUp',
                                                 'nose',
                                                 'noseLeft',
                                                 'noseRight',
                                                 'rightEyeBrowLeft',
                                                 'rightEyeBrowRight',
                                                 'rightEyeBrowUp',
                                                 'rightEyeDown',
                                                 'rightEyeLeft',
                                                 'rightEyeRight',
                                                 'rightEyeUp',
                                                 'rightPupil'}}}},
 'UnmatchedFaces': {'Landmarks': {'Type': {'eyeLeft',
                                           'eyeRight',
                                           'leftEyeBrowLeft',
                                           'leftEyeBrowRight',
                                           'leftEyeBrowUp',
                                           'leftEyeDown',
                                           'leftEyeLeft',
                                           'leftEyeRight',
                                           'leftEyeUp',
                                           'leftPupil',
                                           'mouthDown',
                                           'mouthLeft',
                                           'mouthRight',
                                           'mouthUp',
                                           'nose',
                                           'noseLeft',
                                           'noseRight',
                                           'rightEyeBrowLeft',
                                           'rightEyeBrowRight',
                                           'rightEyeBrowUp',
                                           'rightEyeDown',
                                           'rightEyeLeft',
                                           'rightEyeRight',
                                           'rightEyeUp',
                                           'rightPupil'}}}}

Compares a face in the source input image with each face detected in the target input image.

Note

If the source image contains multiple faces, the service detects the largest face and compares it with each face detected in the target image.

In response, the operation returns an array of face matches ordered by similarity score in descending order. For each face match, the response provides a bounding box of the face, facial landmarks, pose details (pitch, role, and yaw), quality (brightness and sharpness), and confidence value (indicating the level of confidence that the bounding box contains a face). The response also provides a similarity score, which indicates how closely the faces match.

Note

By default, only faces with a similarity score of greater than or equal to 80% are returned in the response. You can change this value by specifying the SimilarityThreshold parameter.

CompareFaces also returns an array of faces that don't match the source image. For each face, it returns a bounding box, confidence value, landmarks, pose details, and quality. The response also returns information about the face in the source image, including the bounding box of the face and confidence value.

If the image doesn't contain Exif metadata, CompareFaces returns orientation information for the source and target images. Use these values to display the images with the correct image orientation.

Note

This is a stateless API operation. That is, data returned by this operation doesn't persist.

For an example, see get-started-exercise-compare-faces.

This operation requires permissions to perform the rekognition:CompareFaces action.

See also: AWS API Documentation

Request Syntax

client.compare_faces(
    SourceImage={
        'Bytes': b'bytes',
        'S3Object': {
            'Bucket': 'string',
            'Name': 'string',
            'Version': 'string'
        }
    },
    TargetImage={
        'Bytes': b'bytes',
        'S3Object': {
            'Bucket': 'string',
            'Name': 'string',
            'Version': 'string'
        }
    },
    SimilarityThreshold=...
)
type SourceImage

dict

param SourceImage

[REQUIRED]

The source image, either as bytes or as an S3 object.

  • Bytes (bytes) --

    Blob of image bytes up to 5 MBs.

  • S3Object (dict) --

    Identifies an S3 object as the image source.

    • Bucket (string) --

      Name of the S3 bucket.

    • Name (string) --

      S3 object key name.

    • Version (string) --

      If the bucket is versioning enabled, you can specify the object version.

type TargetImage

dict

param TargetImage

[REQUIRED]

The target image, either as bytes or as an S3 object.

  • Bytes (bytes) --

    Blob of image bytes up to 5 MBs.

  • S3Object (dict) --

    Identifies an S3 object as the image source.

    • Bucket (string) --

      Name of the S3 bucket.

    • Name (string) --

      S3 object key name.

    • Version (string) --

      If the bucket is versioning enabled, you can specify the object version.

type SimilarityThreshold

float

param SimilarityThreshold

The minimum level of confidence in the face matches that a match must meet to be included in the FaceMatches array.

rtype

dict

returns

Response Syntax

{
    'SourceImageFace': {
        'BoundingBox': {
            'Width': ...,
            'Height': ...,
            'Left': ...,
            'Top': ...
        },
        'Confidence': ...
    },
    'FaceMatches': [
        {
            'Similarity': ...,
            'Face': {
                'BoundingBox': {
                    'Width': ...,
                    'Height': ...,
                    'Left': ...,
                    'Top': ...
                },
                'Confidence': ...,
                'Landmarks': [
                    {
                        'Type': 'eyeLeft'|'eyeRight'|'nose'|'mouthLeft'|'mouthRight'|'leftEyeBrowLeft'|'leftEyeBrowRight'|'leftEyeBrowUp'|'rightEyeBrowLeft'|'rightEyeBrowRight'|'rightEyeBrowUp'|'leftEyeLeft'|'leftEyeRight'|'leftEyeUp'|'leftEyeDown'|'rightEyeLeft'|'rightEyeRight'|'rightEyeUp'|'rightEyeDown'|'noseLeft'|'noseRight'|'mouthUp'|'mouthDown'|'leftPupil'|'rightPupil',
                        'X': ...,
                        'Y': ...
                    },
                ],
                'Pose': {
                    'Roll': ...,
                    'Yaw': ...,
                    'Pitch': ...
                },
                'Quality': {
                    'Brightness': ...,
                    'Sharpness': ...
                }
            }
        },
    ],
    'UnmatchedFaces': [
        {
            'BoundingBox': {
                'Width': ...,
                'Height': ...,
                'Left': ...,
                'Top': ...
            },
            'Confidence': ...,
            'Landmarks': [
                {
                    'Type': 'eyeLeft'|'eyeRight'|'nose'|'mouthLeft'|'mouthRight'|'leftEyeBrowLeft'|'leftEyeBrowRight'|'leftEyeBrowUp'|'rightEyeBrowLeft'|'rightEyeBrowRight'|'rightEyeBrowUp'|'leftEyeLeft'|'leftEyeRight'|'leftEyeUp'|'leftEyeDown'|'rightEyeLeft'|'rightEyeRight'|'rightEyeUp'|'rightEyeDown'|'noseLeft'|'noseRight'|'mouthUp'|'mouthDown'|'leftPupil'|'rightPupil',
                    'X': ...,
                    'Y': ...
                },
            ],
            'Pose': {
                'Roll': ...,
                'Yaw': ...,
                'Pitch': ...
            },
            'Quality': {
                'Brightness': ...,
                'Sharpness': ...
            }
        },
    ],
    'SourceImageOrientationCorrection': 'ROTATE_0'|'ROTATE_90'|'ROTATE_180'|'ROTATE_270',
    'TargetImageOrientationCorrection': 'ROTATE_0'|'ROTATE_90'|'ROTATE_180'|'ROTATE_270'
}

Response Structure

  • (dict) --

    • SourceImageFace (dict) --

      The face in the source image that was used for comparison.

      • BoundingBox (dict) --

        Bounding box of the face.

        • Width (float) --

          Width of the bounding box as a ratio of the overall image width.

        • Height (float) --

          Height of the bounding box as a ratio of the overall image height.

        • Left (float) --

          Left coordinate of the bounding box as a ratio of overall image width.

        • Top (float) --

          Top coordinate of the bounding box as a ratio of overall image height.

      • Confidence (float) --

        Confidence level that the selected bounding box contains a face.

    • FaceMatches (list) --

      An array of faces in the target image that match the source image face. Each CompareFacesMatch object provides the bounding box, the confidence level that the bounding box contains a face, and the similarity score for the face in the bounding box and the face in the source image.

      • (dict) --

        Provides information about a face in a target image that matches the source image face analysed by CompareFaces . The Face property contains the bounding box of the face in the target image. The Similarity property is the confidence that the source image face matches the face in the bounding box.

        • Similarity (float) --

          Level of confidence that the faces match.

        • Face (dict) --

          Provides face metadata (bounding box and confidence that the bounding box actually contains a face).

          • BoundingBox (dict) --

            Bounding box of the face.

            • Width (float) --

              Width of the bounding box as a ratio of the overall image width.

            • Height (float) --

              Height of the bounding box as a ratio of the overall image height.

            • Left (float) --

              Left coordinate of the bounding box as a ratio of overall image width.

            • Top (float) --

              Top coordinate of the bounding box as a ratio of overall image height.

          • Confidence (float) --

            Level of confidence that what the bounding box contains is a face.

          • Landmarks (list) --

            An array of facial landmarks.

            • (dict) --

              Indicates the location of the landmark on the face.

              • Type (string) --

                Type of the landmark.

              • X (float) --

                x-coordinate from the top left of the landmark expressed as the ratio of the width of the image. For example, if the images is 700x200 and the x-coordinate of the landmark is at 350 pixels, this value is 0.5.

              • Y (float) --

                y-coordinate from the top left of the landmark expressed as the ratio of the height of the image. For example, if the images is 700x200 and the y-coordinate of the landmark is at 100 pixels, this value is 0.5.

          • Pose (dict) --

            Indicates the pose of the face as determined by its pitch, roll, and yaw.

            • Roll (float) --

              Value representing the face rotation on the roll axis.

            • Yaw (float) --

              Value representing the face rotation on the yaw axis.

            • Pitch (float) --

              Value representing the face rotation on the pitch axis.

          • Quality (dict) --

            Identifies face image brightness and sharpness.

            • Brightness (float) --

              Value representing brightness of the face. The service returns a value between 0 and 100 (inclusive). A higher value indicates a brighter face image.

            • Sharpness (float) --

              Value representing sharpness of the face. The service returns a value between 0 and 100 (inclusive). A higher value indicates a sharper face image.

    • UnmatchedFaces (list) --

      An array of faces in the target image that did not match the source image face.

      • (dict) --

        Provides face metadata for target image faces that are analysed by CompareFaces and RecognizeCelebrities .

        • BoundingBox (dict) --

          Bounding box of the face.

          • Width (float) --

            Width of the bounding box as a ratio of the overall image width.

          • Height (float) --

            Height of the bounding box as a ratio of the overall image height.

          • Left (float) --

            Left coordinate of the bounding box as a ratio of overall image width.

          • Top (float) --

            Top coordinate of the bounding box as a ratio of overall image height.

        • Confidence (float) --

          Level of confidence that what the bounding box contains is a face.

        • Landmarks (list) --

          An array of facial landmarks.

          • (dict) --

            Indicates the location of the landmark on the face.

            • Type (string) --

              Type of the landmark.

            • X (float) --

              x-coordinate from the top left of the landmark expressed as the ratio of the width of the image. For example, if the images is 700x200 and the x-coordinate of the landmark is at 350 pixels, this value is 0.5.

            • Y (float) --

              y-coordinate from the top left of the landmark expressed as the ratio of the height of the image. For example, if the images is 700x200 and the y-coordinate of the landmark is at 100 pixels, this value is 0.5.

        • Pose (dict) --

          Indicates the pose of the face as determined by its pitch, roll, and yaw.

          • Roll (float) --

            Value representing the face rotation on the roll axis.

          • Yaw (float) --

            Value representing the face rotation on the yaw axis.

          • Pitch (float) --

            Value representing the face rotation on the pitch axis.

        • Quality (dict) --

          Identifies face image brightness and sharpness.

          • Brightness (float) --

            Value representing brightness of the face. The service returns a value between 0 and 100 (inclusive). A higher value indicates a brighter face image.

          • Sharpness (float) --

            Value representing sharpness of the face. The service returns a value between 0 and 100 (inclusive). A higher value indicates a sharper face image.

    • SourceImageOrientationCorrection (string) --

      The orientation of the source image (counterclockwise direction). If your application displays the source image, you can use this value to correct image orientation. The bounding box coordinates returned in SourceImageFace represent the location of the face before the image orientation is corrected.

      Note

      If the source image is in .jpeg format, it might contain exchangeable image (Exif) metadata that includes the image's orientation. If the Exif metadata for the source image populates the orientation field, the value of OrientationCorrection is null and the SourceImageFace bounding box coordinates represent the location of the face after Exif metadata is used to correct the orientation. Images in .png format don't contain Exif metadata.

    • TargetImageOrientationCorrection (string) --

      The orientation of the target image (in counterclockwise direction). If your application displays the target image, you can use this value to correct the orientation of the image. The bounding box coordinates returned in FaceMatches and UnmatchedFaces represent face locations before the image orientation is corrected.

      Note

      If the target image is in .jpg format, it might contain Exif metadata that includes the orientation of the image. If the Exif metadata for the target image populates the orientation field, the value of OrientationCorrection is null and the bounding box coordinates in FaceMatches and UnmatchedFaces represent the location of the face after Exif metadata is used to correct the orientation. Images in .png format don't contain Exif metadata.

DetectFaces (updated) Link ¶
Changes (response)
{'FaceDetails': {'Gender': {'Value': {'Female', 'Male'}},
                 'Landmarks': {'Type': {'eyeLeft',
                                        'eyeRight',
                                        'leftEyeBrowLeft',
                                        'leftEyeBrowRight',
                                        'leftEyeBrowUp',
                                        'leftEyeDown',
                                        'leftEyeLeft',
                                        'leftEyeRight',
                                        'leftEyeUp',
                                        'leftPupil',
                                        'mouthDown',
                                        'mouthLeft',
                                        'mouthRight',
                                        'mouthUp',
                                        'nose',
                                        'noseLeft',
                                        'noseRight',
                                        'rightEyeBrowLeft',
                                        'rightEyeBrowRight',
                                        'rightEyeBrowUp',
                                        'rightEyeDown',
                                        'rightEyeLeft',
                                        'rightEyeRight',
                                        'rightEyeUp',
                                        'rightPupil'}}}}

Detects faces within an image (JPEG or PNG) that is provided as input.

For each face detected, the operation returns face details including a bounding box of the face, a confidence value (that the bounding box contains a face), and a fixed set of attributes such as facial landmarks (for example, coordinates of eye and mouth), gender, presence of beard, sunglasses, etc.

The face-detection algorithm is most effective on frontal faces. For non-frontal or obscured faces, the algorithm may not detect the faces or might detect faces with lower confidence.

Note

This is a stateless API operation. That is, the operation does not persist any data.

For an example, see get-started-exercise-detect-faces.

This operation requires permissions to perform the rekognition:DetectFaces action.

See also: AWS API Documentation

Request Syntax

client.detect_faces(
    Image={
        'Bytes': b'bytes',
        'S3Object': {
            'Bucket': 'string',
            'Name': 'string',
            'Version': 'string'
        }
    },
    Attributes=[
        'DEFAULT'|'ALL',
    ]
)
type Image

dict

param Image

[REQUIRED]

The image in which you want to detect faces. You can specify a blob or an S3 object.

  • Bytes (bytes) --

    Blob of image bytes up to 5 MBs.

  • S3Object (dict) --

    Identifies an S3 object as the image source.

    • Bucket (string) --

      Name of the S3 bucket.

    • Name (string) --

      S3 object key name.

    • Version (string) --

      If the bucket is versioning enabled, you can specify the object version.

type Attributes

list

param Attributes

An array of facial attributes you want to be returned. This can be the default list of attributes or all attributes. If you don't specify a value for Attributes or if you specify ["DEFAULT"] , the API returns the following subset of facial attributes: BoundingBox , Confidence , Pose , Quality and Landmarks . If you provide ["ALL"] , all facial attributes are returned but the operation will take longer to complete.

If you provide both, ["ALL", "DEFAULT"] , the service uses a logical AND operator to determine which attributes to return (in this case, all attributes).

  • (string) --

rtype

dict

returns

Response Syntax

{
    'FaceDetails': [
        {
            'BoundingBox': {
                'Width': ...,
                'Height': ...,
                'Left': ...,
                'Top': ...
            },
            'AgeRange': {
                'Low': 123,
                'High': 123
            },
            'Smile': {
                'Value': True|False,
                'Confidence': ...
            },
            'Eyeglasses': {
                'Value': True|False,
                'Confidence': ...
            },
            'Sunglasses': {
                'Value': True|False,
                'Confidence': ...
            },
            'Gender': {
                'Value': 'Male'|'Female',
                'Confidence': ...
            },
            'Beard': {
                'Value': True|False,
                'Confidence': ...
            },
            'Mustache': {
                'Value': True|False,
                'Confidence': ...
            },
            'EyesOpen': {
                'Value': True|False,
                'Confidence': ...
            },
            'MouthOpen': {
                'Value': True|False,
                'Confidence': ...
            },
            'Emotions': [
                {
                    'Type': 'HAPPY'|'SAD'|'ANGRY'|'CONFUSED'|'DISGUSTED'|'SURPRISED'|'CALM'|'UNKNOWN',
                    'Confidence': ...
                },
            ],
            'Landmarks': [
                {
                    'Type': 'eyeLeft'|'eyeRight'|'nose'|'mouthLeft'|'mouthRight'|'leftEyeBrowLeft'|'leftEyeBrowRight'|'leftEyeBrowUp'|'rightEyeBrowLeft'|'rightEyeBrowRight'|'rightEyeBrowUp'|'leftEyeLeft'|'leftEyeRight'|'leftEyeUp'|'leftEyeDown'|'rightEyeLeft'|'rightEyeRight'|'rightEyeUp'|'rightEyeDown'|'noseLeft'|'noseRight'|'mouthUp'|'mouthDown'|'leftPupil'|'rightPupil',
                    'X': ...,
                    'Y': ...
                },
            ],
            'Pose': {
                'Roll': ...,
                'Yaw': ...,
                'Pitch': ...
            },
            'Quality': {
                'Brightness': ...,
                'Sharpness': ...
            },
            'Confidence': ...
        },
    ],
    'OrientationCorrection': 'ROTATE_0'|'ROTATE_90'|'ROTATE_180'|'ROTATE_270'
}

Response Structure

  • (dict) --

    • FaceDetails (list) --

      Details of each face found in the image.

      • (dict) --

        Structure containing attributes of the face that the algorithm detected.

        • BoundingBox (dict) --

          Bounding box of the face.

          • Width (float) --

            Width of the bounding box as a ratio of the overall image width.

          • Height (float) --

            Height of the bounding box as a ratio of the overall image height.

          • Left (float) --

            Left coordinate of the bounding box as a ratio of overall image width.

          • Top (float) --

            Top coordinate of the bounding box as a ratio of overall image height.

        • AgeRange (dict) --

          The estimated age range, in years, for the face. Low represents the lowest estimated age and High represents the highest estimated age.

          • Low (integer) --

            The lowest estimated age.

          • High (integer) --

            The highest estimated age.

        • Smile (dict) --

          Indicates whether or not the face is smiling, and the confidence level in the determination.

          • Value (boolean) --

            Boolean value that indicates whether the face is smiling or not.

          • Confidence (float) --

            Level of confidence in the determination.

        • Eyeglasses (dict) --

          Indicates whether or not the face is wearing eye glasses, and the confidence level in the determination.

          • Value (boolean) --

            Boolean value that indicates whether the face is wearing eye glasses or not.

          • Confidence (float) --

            Level of confidence in the determination.

        • Sunglasses (dict) --

          Indicates whether or not the face is wearing sunglasses, and the confidence level in the determination.

          • Value (boolean) --

            Boolean value that indicates whether the face is wearing sunglasses or not.

          • Confidence (float) --

            Level of confidence in the determination.

        • Gender (dict) --

          Gender of the face and the confidence level in the determination.

          • Value (string) --

            Gender of the face.

          • Confidence (float) --

            Level of confidence in the determination.

        • Beard (dict) --

          Indicates whether or not the face has a beard, and the confidence level in the determination.

          • Value (boolean) --

            Boolean value that indicates whether the face has beard or not.

          • Confidence (float) --

            Level of confidence in the determination.

        • Mustache (dict) --

          Indicates whether or not the face has a mustache, and the confidence level in the determination.

          • Value (boolean) --

            Boolean value that indicates whether the face has mustache or not.

          • Confidence (float) --

            Level of confidence in the determination.

        • EyesOpen (dict) --

          Indicates whether or not the eyes on the face are open, and the confidence level in the determination.

          • Value (boolean) --

            Boolean value that indicates whether the eyes on the face are open.

          • Confidence (float) --

            Level of confidence in the determination.

        • MouthOpen (dict) --

          Indicates whether or not the mouth on the face is open, and the confidence level in the determination.

          • Value (boolean) --

            Boolean value that indicates whether the mouth on the face is open or not.

          • Confidence (float) --

            Level of confidence in the determination.

        • Emotions (list) --

          The emotions detected on the face, and the confidence level in the determination. For example, HAPPY, SAD, and ANGRY.

          • (dict) --

            The emotions detected on the face, and the confidence level in the determination. For example, HAPPY, SAD, and ANGRY.

            • Type (string) --

              Type of emotion detected.

            • Confidence (float) --

              Level of confidence in the determination.

        • Landmarks (list) --

          Indicates the location of landmarks on the face.

          • (dict) --

            Indicates the location of the landmark on the face.

            • Type (string) --

              Type of the landmark.

            • X (float) --

              x-coordinate from the top left of the landmark expressed as the ratio of the width of the image. For example, if the images is 700x200 and the x-coordinate of the landmark is at 350 pixels, this value is 0.5.

            • Y (float) --

              y-coordinate from the top left of the landmark expressed as the ratio of the height of the image. For example, if the images is 700x200 and the y-coordinate of the landmark is at 100 pixels, this value is 0.5.

        • Pose (dict) --

          Indicates the pose of the face as determined by its pitch, roll, and yaw.

          • Roll (float) --

            Value representing the face rotation on the roll axis.

          • Yaw (float) --

            Value representing the face rotation on the yaw axis.

          • Pitch (float) --

            Value representing the face rotation on the pitch axis.

        • Quality (dict) --

          Identifies image brightness and sharpness.

          • Brightness (float) --

            Value representing brightness of the face. The service returns a value between 0 and 100 (inclusive). A higher value indicates a brighter face image.

          • Sharpness (float) --

            Value representing sharpness of the face. The service returns a value between 0 and 100 (inclusive). A higher value indicates a sharper face image.

        • Confidence (float) --

          Confidence level that the bounding box contains a face (and not a different object such as a tree).

    • OrientationCorrection (string) --

      The orientation of the input image (counter-clockwise direction). If your application displays the image, you can use this value to correct image orientation. The bounding box coordinates returned in FaceDetails represent face locations before the image orientation is corrected.

      Note

      If the input image is in .jpeg format, it might contain exchangeable image (Exif) metadata that includes the image's orientation. If so, and the Exif metadata for the input image populates the orientation field, the value of OrientationCorrection is null and the FaceDetails bounding box coordinates represent face locations after Exif metadata is used to correct the image orientation. Images in .png format don't contain Exif metadata.

IndexFaces (updated) Link ¶
Changes (response)
{'FaceRecords': {'FaceDetail': {'Gender': {'Value': {'Female', 'Male'}},
                                'Landmarks': {'Type': {'eyeLeft',
                                                       'eyeRight',
                                                       'leftEyeBrowLeft',
                                                       'leftEyeBrowRight',
                                                       'leftEyeBrowUp',
                                                       'leftEyeDown',
                                                       'leftEyeLeft',
                                                       'leftEyeRight',
                                                       'leftEyeUp',
                                                       'leftPupil',
                                                       'mouthDown',
                                                       'mouthLeft',
                                                       'mouthRight',
                                                       'mouthUp',
                                                       'nose',
                                                       'noseLeft',
                                                       'noseRight',
                                                       'rightEyeBrowLeft',
                                                       'rightEyeBrowRight',
                                                       'rightEyeBrowUp',
                                                       'rightEyeDown',
                                                       'rightEyeLeft',
                                                       'rightEyeRight',
                                                       'rightEyeUp',
                                                       'rightPupil'}}}}}

Detects faces in the input image and adds them to the specified collection.

Amazon Rekognition does not save the actual faces detected. Instead, the underlying detection algorithm first detects the faces in the input image, and for each face extracts facial features into a feature vector, and stores it in the back-end database. Amazon Rekognition uses feature vectors when performing face match and search operations using the and operations.

If you provide the optional externalImageID for the input image you provided, Amazon Rekognition associates this ID with all faces that it detects. When you call the operation, the response returns the external ID. You can use this external image ID to create a client-side index to associate the faces with each image. You can then use the index to find all faces in an image.

In response, the operation returns an array of metadata for all detected faces. This includes, the bounding box of the detected face, confidence value (indicating the bounding box contains a face), a face ID assigned by the service for each face that is detected and stored, and an image ID assigned by the service for the input image. If you request all facial attributes (using the detectionAttributes parameter, Amazon Rekognition returns detailed facial attributes such as facial landmarks (for example, location of eye and mount) and other facial attributes such gender. If you provide the same image, specify the same collection, and use the same external ID in the IndexFaces operation, Amazon Rekognition doesn't save duplicate face metadata.

For an example, see example2.

This operation requires permissions to perform the rekognition:IndexFaces action.

See also: AWS API Documentation

Request Syntax

client.index_faces(
    CollectionId='string',
    Image={
        'Bytes': b'bytes',
        'S3Object': {
            'Bucket': 'string',
            'Name': 'string',
            'Version': 'string'
        }
    },
    ExternalImageId='string',
    DetectionAttributes=[
        'DEFAULT'|'ALL',
    ]
)
type CollectionId

string

param CollectionId

[REQUIRED]

The ID of an existing collection to which you want to add the faces that are detected in the input images.

type Image

dict

param Image

[REQUIRED]

The input image as bytes or an S3 object.

  • Bytes (bytes) --

    Blob of image bytes up to 5 MBs.

  • S3Object (dict) --

    Identifies an S3 object as the image source.

    • Bucket (string) --

      Name of the S3 bucket.

    • Name (string) --

      S3 object key name.

    • Version (string) --

      If the bucket is versioning enabled, you can specify the object version.

type ExternalImageId

string

param ExternalImageId

ID you want to assign to all the faces detected in the image.

type DetectionAttributes

list

param DetectionAttributes

An array of facial attributes that you want to be returned. This can be the default list of attributes or all attributes. If you don't specify a value for Attributes or if you specify ["DEFAULT"] , the API returns the following subset of facial attributes: BoundingBox , Confidence , Pose , Quality and Landmarks . If you provide ["ALL"] , all facial attributes are returned but the operation will take longer to complete.

If you provide both, ["ALL", "DEFAULT"] , the service uses a logical AND operator to determine which attributes to return (in this case, all attributes).

  • (string) --

rtype

dict

returns

Response Syntax

{
    'FaceRecords': [
        {
            'Face': {
                'FaceId': 'string',
                'BoundingBox': {
                    'Width': ...,
                    'Height': ...,
                    'Left': ...,
                    'Top': ...
                },
                'ImageId': 'string',
                'ExternalImageId': 'string',
                'Confidence': ...
            },
            'FaceDetail': {
                'BoundingBox': {
                    'Width': ...,
                    'Height': ...,
                    'Left': ...,
                    'Top': ...
                },
                'AgeRange': {
                    'Low': 123,
                    'High': 123
                },
                'Smile': {
                    'Value': True|False,
                    'Confidence': ...
                },
                'Eyeglasses': {
                    'Value': True|False,
                    'Confidence': ...
                },
                'Sunglasses': {
                    'Value': True|False,
                    'Confidence': ...
                },
                'Gender': {
                    'Value': 'Male'|'Female',
                    'Confidence': ...
                },
                'Beard': {
                    'Value': True|False,
                    'Confidence': ...
                },
                'Mustache': {
                    'Value': True|False,
                    'Confidence': ...
                },
                'EyesOpen': {
                    'Value': True|False,
                    'Confidence': ...
                },
                'MouthOpen': {
                    'Value': True|False,
                    'Confidence': ...
                },
                'Emotions': [
                    {
                        'Type': 'HAPPY'|'SAD'|'ANGRY'|'CONFUSED'|'DISGUSTED'|'SURPRISED'|'CALM'|'UNKNOWN',
                        'Confidence': ...
                    },
                ],
                'Landmarks': [
                    {
                        'Type': 'eyeLeft'|'eyeRight'|'nose'|'mouthLeft'|'mouthRight'|'leftEyeBrowLeft'|'leftEyeBrowRight'|'leftEyeBrowUp'|'rightEyeBrowLeft'|'rightEyeBrowRight'|'rightEyeBrowUp'|'leftEyeLeft'|'leftEyeRight'|'leftEyeUp'|'leftEyeDown'|'rightEyeLeft'|'rightEyeRight'|'rightEyeUp'|'rightEyeDown'|'noseLeft'|'noseRight'|'mouthUp'|'mouthDown'|'leftPupil'|'rightPupil',
                        'X': ...,
                        'Y': ...
                    },
                ],
                'Pose': {
                    'Roll': ...,
                    'Yaw': ...,
                    'Pitch': ...
                },
                'Quality': {
                    'Brightness': ...,
                    'Sharpness': ...
                },
                'Confidence': ...
            }
        },
    ],
    'OrientationCorrection': 'ROTATE_0'|'ROTATE_90'|'ROTATE_180'|'ROTATE_270'
}

Response Structure

  • (dict) --

    • FaceRecords (list) --

      An array of faces detected and added to the collection. For more information, see howitworks-index-faces.

      • (dict) --

        Object containing both the face metadata (stored in the back-end database) and facial attributes that are detected but aren't stored in the database.

        • Face (dict) --

          Describes the face properties such as the bounding box, face ID, image ID of the input image, and external image ID that you assigned.

          • FaceId (string) --

            Unique identifier that Amazon Rekognition assigns to the face.

          • BoundingBox (dict) --

            Bounding box of the face.

            • Width (float) --

              Width of the bounding box as a ratio of the overall image width.

            • Height (float) --

              Height of the bounding box as a ratio of the overall image height.

            • Left (float) --

              Left coordinate of the bounding box as a ratio of overall image width.

            • Top (float) --

              Top coordinate of the bounding box as a ratio of overall image height.

          • ImageId (string) --

            Unique identifier that Amazon Rekognition assigns to the input image.

          • ExternalImageId (string) --

            Identifier that you assign to all the faces in the input image.

          • Confidence (float) --

            Confidence level that the bounding box contains a face (and not a different object such as a tree).

        • FaceDetail (dict) --

          Structure containing attributes of the face that the algorithm detected.

          • BoundingBox (dict) --

            Bounding box of the face.

            • Width (float) --

              Width of the bounding box as a ratio of the overall image width.

            • Height (float) --

              Height of the bounding box as a ratio of the overall image height.

            • Left (float) --

              Left coordinate of the bounding box as a ratio of overall image width.

            • Top (float) --

              Top coordinate of the bounding box as a ratio of overall image height.

          • AgeRange (dict) --

            The estimated age range, in years, for the face. Low represents the lowest estimated age and High represents the highest estimated age.

            • Low (integer) --

              The lowest estimated age.

            • High (integer) --

              The highest estimated age.

          • Smile (dict) --

            Indicates whether or not the face is smiling, and the confidence level in the determination.

            • Value (boolean) --

              Boolean value that indicates whether the face is smiling or not.

            • Confidence (float) --

              Level of confidence in the determination.

          • Eyeglasses (dict) --

            Indicates whether or not the face is wearing eye glasses, and the confidence level in the determination.

            • Value (boolean) --

              Boolean value that indicates whether the face is wearing eye glasses or not.

            • Confidence (float) --

              Level of confidence in the determination.

          • Sunglasses (dict) --

            Indicates whether or not the face is wearing sunglasses, and the confidence level in the determination.

            • Value (boolean) --

              Boolean value that indicates whether the face is wearing sunglasses or not.

            • Confidence (float) --

              Level of confidence in the determination.

          • Gender (dict) --

            Gender of the face and the confidence level in the determination.

            • Value (string) --

              Gender of the face.

            • Confidence (float) --

              Level of confidence in the determination.

          • Beard (dict) --

            Indicates whether or not the face has a beard, and the confidence level in the determination.

            • Value (boolean) --

              Boolean value that indicates whether the face has beard or not.

            • Confidence (float) --

              Level of confidence in the determination.

          • Mustache (dict) --

            Indicates whether or not the face has a mustache, and the confidence level in the determination.

            • Value (boolean) --

              Boolean value that indicates whether the face has mustache or not.

            • Confidence (float) --

              Level of confidence in the determination.

          • EyesOpen (dict) --

            Indicates whether or not the eyes on the face are open, and the confidence level in the determination.

            • Value (boolean) --

              Boolean value that indicates whether the eyes on the face are open.

            • Confidence (float) --

              Level of confidence in the determination.

          • MouthOpen (dict) --

            Indicates whether or not the mouth on the face is open, and the confidence level in the determination.

            • Value (boolean) --

              Boolean value that indicates whether the mouth on the face is open or not.

            • Confidence (float) --

              Level of confidence in the determination.

          • Emotions (list) --

            The emotions detected on the face, and the confidence level in the determination. For example, HAPPY, SAD, and ANGRY.

            • (dict) --

              The emotions detected on the face, and the confidence level in the determination. For example, HAPPY, SAD, and ANGRY.

              • Type (string) --

                Type of emotion detected.

              • Confidence (float) --

                Level of confidence in the determination.

          • Landmarks (list) --

            Indicates the location of landmarks on the face.

            • (dict) --

              Indicates the location of the landmark on the face.

              • Type (string) --

                Type of the landmark.

              • X (float) --

                x-coordinate from the top left of the landmark expressed as the ratio of the width of the image. For example, if the images is 700x200 and the x-coordinate of the landmark is at 350 pixels, this value is 0.5.

              • Y (float) --

                y-coordinate from the top left of the landmark expressed as the ratio of the height of the image. For example, if the images is 700x200 and the y-coordinate of the landmark is at 100 pixels, this value is 0.5.

          • Pose (dict) --

            Indicates the pose of the face as determined by its pitch, roll, and yaw.

            • Roll (float) --

              Value representing the face rotation on the roll axis.

            • Yaw (float) --

              Value representing the face rotation on the yaw axis.

            • Pitch (float) --

              Value representing the face rotation on the pitch axis.

          • Quality (dict) --

            Identifies image brightness and sharpness.

            • Brightness (float) --

              Value representing brightness of the face. The service returns a value between 0 and 100 (inclusive). A higher value indicates a brighter face image.

            • Sharpness (float) --

              Value representing sharpness of the face. The service returns a value between 0 and 100 (inclusive). A higher value indicates a sharper face image.

          • Confidence (float) --

            Confidence level that the bounding box contains a face (and not a different object such as a tree).

    • OrientationCorrection (string) --

      The orientation of the input image (counterclockwise direction). If your application displays the image, you can use this value to correct image orientation. The bounding box coordinates returned in FaceRecords represent face locations before the image orientation is corrected.

      Note

      If the input image is in jpeg format, it might contain exchangeable image (Exif) metadata. If so, and the Exif metadata populates the orientation field, the value of OrientationCorrection is null and the bounding box coordinates in FaceRecords represent face locations after Exif metadata is used to correct the image orientation. Images in .png format don't contain Exif metadata.

RecognizeCelebrities (updated) Link ¶
Changes (response)
{'CelebrityFaces': {'Face': {'Landmarks': {'Type': {'eyeLeft',
                                                    'eyeRight',
                                                    'leftEyeBrowLeft',
                                                    'leftEyeBrowRight',
                                                    'leftEyeBrowUp',
                                                    'leftEyeDown',
                                                    'leftEyeLeft',
                                                    'leftEyeRight',
                                                    'leftEyeUp',
                                                    'leftPupil',
                                                    'mouthDown',
                                                    'mouthLeft',
                                                    'mouthRight',
                                                    'mouthUp',
                                                    'nose',
                                                    'noseLeft',
                                                    'noseRight',
                                                    'rightEyeBrowLeft',
                                                    'rightEyeBrowRight',
                                                    'rightEyeBrowUp',
                                                    'rightEyeDown',
                                                    'rightEyeLeft',
                                                    'rightEyeRight',
                                                    'rightEyeUp',
                                                    'rightPupil'}}}},
 'UnrecognizedFaces': {'Landmarks': {'Type': {'eyeLeft',
                                              'eyeRight',
                                              'leftEyeBrowLeft',
                                              'leftEyeBrowRight',
                                              'leftEyeBrowUp',
                                              'leftEyeDown',
                                              'leftEyeLeft',
                                              'leftEyeRight',
                                              'leftEyeUp',
                                              'leftPupil',
                                              'mouthDown',
                                              'mouthLeft',
                                              'mouthRight',
                                              'mouthUp',
                                              'nose',
                                              'noseLeft',
                                              'noseRight',
                                              'rightEyeBrowLeft',
                                              'rightEyeBrowRight',
                                              'rightEyeBrowUp',
                                              'rightEyeDown',
                                              'rightEyeLeft',
                                              'rightEyeRight',
                                              'rightEyeUp',
                                              'rightPupil'}}}}

Returns an array of celebrities recognized in the input image. The image is passed either as base64-encoded image bytes or as a reference to an image in an Amazon S3 bucket. The image must be either a PNG or JPEG formatted file. For more information, see celebrity-recognition.

RecognizeCelebrities returns the 15 largest faces in the image. It lists recognized celebrities in the CelebrityFaces list and unrecognized faces in the UnrecognizedFaces list. The operation doesn't return celebrities whose face sizes are smaller than the largest 15 faces in the image.

For each celebrity recognized, the API returns a Celebrity object. The Celebrity object contains the celebrity name, ID, URL links to additional information, match confidence, and a ComparedFace object that you can use to locate the celebrity's face on the image.

Rekognition does not retain information about which images a celebrity has been recognized in. Your application must store this information and use the Celebrity ID property as a unique identifier for the celebrity. If you don't store the celebrity name or additional information URLs returned by RecognizeCelebrities , you will need the ID to identify the celebrity in a call to the operation.

For an example, see recognize-celebrities-tutorial.

This operation requires permissions to perform the rekognition:RecognizeCelebrities operation.

See also: AWS API Documentation

Request Syntax

client.recognize_celebrities(
    Image={
        'Bytes': b'bytes',
        'S3Object': {
            'Bucket': 'string',
            'Name': 'string',
            'Version': 'string'
        }
    }
)
type Image

dict

param Image

[REQUIRED]

The input image to use for celebrity recognition.

  • Bytes (bytes) --

    Blob of image bytes up to 5 MBs.

  • S3Object (dict) --

    Identifies an S3 object as the image source.

    • Bucket (string) --

      Name of the S3 bucket.

    • Name (string) --

      S3 object key name.

    • Version (string) --

      If the bucket is versioning enabled, you can specify the object version.

rtype

dict

returns

Response Syntax

{
    'CelebrityFaces': [
        {
            'Urls': [
                'string',
            ],
            'Name': 'string',
            'Id': 'string',
            'Face': {
                'BoundingBox': {
                    'Width': ...,
                    'Height': ...,
                    'Left': ...,
                    'Top': ...
                },
                'Confidence': ...,
                'Landmarks': [
                    {
                        'Type': 'eyeLeft'|'eyeRight'|'nose'|'mouthLeft'|'mouthRight'|'leftEyeBrowLeft'|'leftEyeBrowRight'|'leftEyeBrowUp'|'rightEyeBrowLeft'|'rightEyeBrowRight'|'rightEyeBrowUp'|'leftEyeLeft'|'leftEyeRight'|'leftEyeUp'|'leftEyeDown'|'rightEyeLeft'|'rightEyeRight'|'rightEyeUp'|'rightEyeDown'|'noseLeft'|'noseRight'|'mouthUp'|'mouthDown'|'leftPupil'|'rightPupil',
                        'X': ...,
                        'Y': ...
                    },
                ],
                'Pose': {
                    'Roll': ...,
                    'Yaw': ...,
                    'Pitch': ...
                },
                'Quality': {
                    'Brightness': ...,
                    'Sharpness': ...
                }
            },
            'MatchConfidence': ...
        },
    ],
    'UnrecognizedFaces': [
        {
            'BoundingBox': {
                'Width': ...,
                'Height': ...,
                'Left': ...,
                'Top': ...
            },
            'Confidence': ...,
            'Landmarks': [
                {
                    'Type': 'eyeLeft'|'eyeRight'|'nose'|'mouthLeft'|'mouthRight'|'leftEyeBrowLeft'|'leftEyeBrowRight'|'leftEyeBrowUp'|'rightEyeBrowLeft'|'rightEyeBrowRight'|'rightEyeBrowUp'|'leftEyeLeft'|'leftEyeRight'|'leftEyeUp'|'leftEyeDown'|'rightEyeLeft'|'rightEyeRight'|'rightEyeUp'|'rightEyeDown'|'noseLeft'|'noseRight'|'mouthUp'|'mouthDown'|'leftPupil'|'rightPupil',
                    'X': ...,
                    'Y': ...
                },
            ],
            'Pose': {
                'Roll': ...,
                'Yaw': ...,
                'Pitch': ...
            },
            'Quality': {
                'Brightness': ...,
                'Sharpness': ...
            }
        },
    ],
    'OrientationCorrection': 'ROTATE_0'|'ROTATE_90'|'ROTATE_180'|'ROTATE_270'
}

Response Structure

  • (dict) --

    • CelebrityFaces (list) --

      Details about each celebrity found in the image. Amazon Rekognition can detect a maximum of 15 celebrities in an image.

      • (dict) --

        Provides information about a celebrity recognized by the operation.

        • Urls (list) --

          An array of URLs pointing to additional information about the celebrity. If there is no additional information about the celebrity, this list is empty.

          • (string) --

        • Name (string) --

          The name of the celebrity.

        • Id (string) --

          A unique identifier for the celebrity.

        • Face (dict) --

          Provides information about the celebrity's face, such as its location on the image.

          • BoundingBox (dict) --

            Bounding box of the face.

            • Width (float) --

              Width of the bounding box as a ratio of the overall image width.

            • Height (float) --

              Height of the bounding box as a ratio of the overall image height.

            • Left (float) --

              Left coordinate of the bounding box as a ratio of overall image width.

            • Top (float) --

              Top coordinate of the bounding box as a ratio of overall image height.

          • Confidence (float) --

            Level of confidence that what the bounding box contains is a face.

          • Landmarks (list) --

            An array of facial landmarks.

            • (dict) --

              Indicates the location of the landmark on the face.

              • Type (string) --

                Type of the landmark.

              • X (float) --

                x-coordinate from the top left of the landmark expressed as the ratio of the width of the image. For example, if the images is 700x200 and the x-coordinate of the landmark is at 350 pixels, this value is 0.5.

              • Y (float) --

                y-coordinate from the top left of the landmark expressed as the ratio of the height of the image. For example, if the images is 700x200 and the y-coordinate of the landmark is at 100 pixels, this value is 0.5.

          • Pose (dict) --

            Indicates the pose of the face as determined by its pitch, roll, and yaw.

            • Roll (float) --

              Value representing the face rotation on the roll axis.

            • Yaw (float) --

              Value representing the face rotation on the yaw axis.

            • Pitch (float) --

              Value representing the face rotation on the pitch axis.

          • Quality (dict) --

            Identifies face image brightness and sharpness.

            • Brightness (float) --

              Value representing brightness of the face. The service returns a value between 0 and 100 (inclusive). A higher value indicates a brighter face image.

            • Sharpness (float) --

              Value representing sharpness of the face. The service returns a value between 0 and 100 (inclusive). A higher value indicates a sharper face image.

        • MatchConfidence (float) --

          The confidence, in percentage, that Rekognition has that the recognized face is the celebrity.

    • UnrecognizedFaces (list) --

      Details about each unrecognized face in the image.

      • (dict) --

        Provides face metadata for target image faces that are analysed by CompareFaces and RecognizeCelebrities .

        • BoundingBox (dict) --

          Bounding box of the face.

          • Width (float) --

            Width of the bounding box as a ratio of the overall image width.

          • Height (float) --

            Height of the bounding box as a ratio of the overall image height.

          • Left (float) --

            Left coordinate of the bounding box as a ratio of overall image width.

          • Top (float) --

            Top coordinate of the bounding box as a ratio of overall image height.

        • Confidence (float) --

          Level of confidence that what the bounding box contains is a face.

        • Landmarks (list) --

          An array of facial landmarks.

          • (dict) --

            Indicates the location of the landmark on the face.

            • Type (string) --

              Type of the landmark.

            • X (float) --

              x-coordinate from the top left of the landmark expressed as the ratio of the width of the image. For example, if the images is 700x200 and the x-coordinate of the landmark is at 350 pixels, this value is 0.5.

            • Y (float) --

              y-coordinate from the top left of the landmark expressed as the ratio of the height of the image. For example, if the images is 700x200 and the y-coordinate of the landmark is at 100 pixels, this value is 0.5.

        • Pose (dict) --

          Indicates the pose of the face as determined by its pitch, roll, and yaw.

          • Roll (float) --

            Value representing the face rotation on the roll axis.

          • Yaw (float) --

            Value representing the face rotation on the yaw axis.

          • Pitch (float) --

            Value representing the face rotation on the pitch axis.

        • Quality (dict) --

          Identifies face image brightness and sharpness.

          • Brightness (float) --

            Value representing brightness of the face. The service returns a value between 0 and 100 (inclusive). A higher value indicates a brighter face image.

          • Sharpness (float) --

            Value representing sharpness of the face. The service returns a value between 0 and 100 (inclusive). A higher value indicates a sharper face image.

    • OrientationCorrection (string) --

      The orientation of the input image (counterclockwise direction). If your application displays the image, you can use this value to correct the orientation. The bounding box coordinates returned in CelebrityFaces and UnrecognizedFaces represent face locations before the image orientation is corrected.

      Note

      If the input image is in .jpeg format, it might contain exchangeable image (Exif) metadata that includes the image's orientation. If so, and the Exif metadata for the input image populates the orientation field, the value of OrientationCorrection is null and the CelebrityFaces and UnrecognizedFaces bounding box coordinates represent face locations after Exif metadata is used to correct the image orientation. Images in .png format don't contain Exif metadata.