Menu
Amazon Rekognition
Developer Guide

DetectFaces

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 Exercise 2: Detect Faces (API).

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

Request Syntax

Copy
{ "Attributes": [ "string" ], "Image": { "Bytes": blob, "S3Object": { "Bucket": "string", "Name": "string", "Version": "string" } } }

Request Parameters

The request accepts the following data in JSON format.

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).

Type: Array of strings

Valid Values: DEFAULT | ALL

Required: No

Image

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

Type: Image object

Required: Yes

Response Syntax

Copy
{ "FaceDetails": [ { "AgeRange": { "High": number, "Low": number }, "Beard": { "Confidence": number, "Value": boolean }, "BoundingBox": { "Height": number, "Left": number, "Top": number, "Width": number }, "Confidence": number, "Emotions": [ { "Confidence": number, "Type": "string" } ], "Eyeglasses": { "Confidence": number, "Value": boolean }, "EyesOpen": { "Confidence": number, "Value": boolean }, "Gender": { "Confidence": number, "Value": "string" }, "Landmarks": [ { "Type": "string", "X": number, "Y": number } ], "MouthOpen": { "Confidence": number, "Value": boolean }, "Mustache": { "Confidence": number, "Value": boolean }, "Pose": { "Pitch": number, "Roll": number, "Yaw": number }, "Quality": { "Brightness": number, "Sharpness": number }, "Smile": { "Confidence": number, "Value": boolean }, "Sunglasses": { "Confidence": number, "Value": boolean } } ], "OrientationCorrection": "string" }

Response Elements

If the action is successful, the service sends back an HTTP 200 response.

The following data is returned in JSON format by the service.

FaceDetails

Details of each face found in the image.

Type: Array of FaceDetail objects

OrientationCorrection

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.

Type: String

Valid Values: ROTATE_0 | ROTATE_90 | ROTATE_180 | ROTATE_270

Errors

AccessDeniedException

You are not authorized to perform the action.

HTTP Status Code: 400

ImageTooLargeException

The input image size exceeds the allowed limit. For more information, see Limits in Amazon Rekognition.

HTTP Status Code: 400

InternalServerError

Amazon Rekognition experienced a service issue. Try your call again.

HTTP Status Code: 500

InvalidImageFormatException

The provided image format is not supported.

HTTP Status Code: 400

InvalidParameterException

Input parameter violated a constraint. Validate your parameter before calling the API operation again.

HTTP Status Code: 400

InvalidS3ObjectException

Amazon Rekognition is unable to access the S3 object specified in the request.

HTTP Status Code: 400

ProvisionedThroughputExceededException

The number of requests exceeded your throughput limit. If you want to increase this limit, contact Amazon Rekognition.

HTTP Status Code: 400

ThrottlingException

Amazon Rekognition is temporarily unable to process the request. Try your call again.

HTTP Status Code: 500

Example

Example Request

The following example shows a request that detects faces in an image (crowd.jpg) stored in an Amazon S3 bucket (example-photos).

Sample Request

Copy
POST https://rekognition.us-west-2.amazonaws.com/ HTTP/1.1 Host: rekognition.us-west-2.amazonaws.com Accept-Encoding: identity Content-Length: 77 X-Amz-Target: RekognitionService.DetectFaces X-Amz-Date: 20170104T233701Z User-Agent: aws-cli/1.11.25 Python/2.7.9 Windows/8 botocore/1.4.82 Content-Type: application/x-amz-json-1.1 Authorization: AWS4-HMAC-SHA256 Credential=XXXXXXXX/20170104/us-west-2/rekognition/aws4_request, SignedHeaders=content-type;host;x-amz-date;x-amz-target, Signature=XXXXXXXX { "Image":{ "S3Object":{ "Bucket":"example-photos", "Name":"crowd.jpg" } } }

Sample Response

Copy
HTTP/1.1 200 OK Content-Type: application/x-amz-json-1.1 Date: Wed, 04 Jan 2017 23:37:03 GMT x-amzn-RequestId: b1827570-d2d6-11e6-a51e-73b99a9bb0b9 Content-Length: 1355 Connection: keep-alive { "FaceDetails":[ { "BoundingBox":{ "Height":0.18000000715255737, "Left":0.5555555820465088, "Top":0.33666667342185974, "Width":0.23999999463558197 }, "Confidence":100.0, "Landmarks":[ { "Type":"eyeLeft", "X":0.6394737362861633, "Y":0.40819624066352844 }, { "Type":"eyeRight", "X":0.7266660928726196, "Y":0.41039225459098816 }, { "Type":"nose", "X":0.6912462115287781, "Y":0.44240960478782654 }, { "Type":"mouthLeft", "X":0.6306198239326477, "Y":0.46700039505958557 }, { "Type":"mouthRight", "X":0.7215608954429626, "Y":0.47114261984825134 } ], "Pose":{ "Pitch":4.050806522369385, "Roll":0.9950747489929199, "Yaw":13.693790435791016 }, "Quality":{ "Brightness":37.60169982910156, "Sharpness":80.0 } }, { "BoundingBox":{ "Height":0.16555555164813995, "Left":0.3096296191215515, "Top":0.7066666483879089, "Width":0.22074073553085327 }, "Confidence":99.99998474121094, "Landmarks":[ { "Type":"eyeLeft", "X":0.3767718970775604, "Y":0.7863991856575012 }, { "Type":"eyeRight", "X":0.4517287313938141, "Y":0.7715709209442139 }, { "Type":"nose", "X":0.42001065611839294, "Y":0.8192070126533508 }, { "Type":"mouthLeft", "X":0.3915625810623169, "Y":0.8374140858650208 }, { "Type":"mouthRight", "X":0.46825936436653137, "Y":0.823401689529419 } ], "Pose":{ "Pitch":-16.320178985595703, "Roll":-15.097439765930176, "Yaw":-5.771541118621826 }, "Quality":{ "Brightness":31.440860748291016, "Sharpness":60.000003814697266 } } ], "OrientationCorrection":"ROTATE_0" }

See Also

For more information about using this API in one of the language-specific AWS SDKs, see the following: