DetectFacesCommand

Detects faces within an image that is provided as input.

DetectFaces detects the 100 largest faces in the image. For each face detected, the operation returns face details. These details include 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), pose, presence of facial occlusion, and so on.

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

You pass the input image either as base64-encoded image bytes or as a reference to an image in an Amazon S3 bucket. If you use the AWS CLI to call Amazon Rekognition operations, passing image bytes is not supported. The image must be either a PNG or JPEG formatted file.

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

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

Example Syntax

Use a bare-bones client and the command you need to make an API call.

import { RekognitionClient, DetectFacesCommand } from "@aws-sdk/client-rekognition"; // ES Modules import
// const { RekognitionClient, DetectFacesCommand } = require("@aws-sdk/client-rekognition"); // CommonJS import
const client = new RekognitionClient(config);
const input = { // DetectFacesRequest
  Image: { // Image
    Bytes: new Uint8Array(), // e.g. Buffer.from("") or new TextEncoder().encode("")
    S3Object: { // S3Object
      Bucket: "STRING_VALUE",
      Name: "STRING_VALUE",
      Version: "STRING_VALUE",
    },
  },
  Attributes: [ // Attributes
    "DEFAULT" || "ALL" || "AGE_RANGE" || "BEARD" || "EMOTIONS" || "EYE_DIRECTION" || "EYEGLASSES" || "EYES_OPEN" || "GENDER" || "MOUTH_OPEN" || "MUSTACHE" || "FACE_OCCLUDED" || "SMILE" || "SUNGLASSES",
  ],
};
const command = new DetectFacesCommand(input);
const response = await client.send(command);
// { // DetectFacesResponse
//   FaceDetails: [ // FaceDetailList
//     { // FaceDetail
//       BoundingBox: { // BoundingBox
//         Width: Number("float"),
//         Height: Number("float"),
//         Left: Number("float"),
//         Top: Number("float"),
//       },
//       AgeRange: { // AgeRange
//         Low: Number("int"),
//         High: Number("int"),
//       },
//       Smile: { // Smile
//         Value: true || false,
//         Confidence: Number("float"),
//       },
//       Eyeglasses: { // Eyeglasses
//         Value: true || false,
//         Confidence: Number("float"),
//       },
//       Sunglasses: { // Sunglasses
//         Value: true || false,
//         Confidence: Number("float"),
//       },
//       Gender: { // Gender
//         Value: "Male" || "Female",
//         Confidence: Number("float"),
//       },
//       Beard: { // Beard
//         Value: true || false,
//         Confidence: Number("float"),
//       },
//       Mustache: { // Mustache
//         Value: true || false,
//         Confidence: Number("float"),
//       },
//       EyesOpen: { // EyeOpen
//         Value: true || false,
//         Confidence: Number("float"),
//       },
//       MouthOpen: { // MouthOpen
//         Value: true || false,
//         Confidence: Number("float"),
//       },
//       Emotions: [ // Emotions
//         { // Emotion
//           Type: "HAPPY" || "SAD" || "ANGRY" || "CONFUSED" || "DISGUSTED" || "SURPRISED" || "CALM" || "UNKNOWN" || "FEAR",
//           Confidence: Number("float"),
//         },
//       ],
//       Landmarks: [ // Landmarks
//         { // Landmark
//           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" || "upperJawlineLeft" || "midJawlineLeft" || "chinBottom" || "midJawlineRight" || "upperJawlineRight",
//           X: Number("float"),
//           Y: Number("float"),
//         },
//       ],
//       Pose: { // Pose
//         Roll: Number("float"),
//         Yaw: Number("float"),
//         Pitch: Number("float"),
//       },
//       Quality: { // ImageQuality
//         Brightness: Number("float"),
//         Sharpness: Number("float"),
//       },
//       Confidence: Number("float"),
//       FaceOccluded: { // FaceOccluded
//         Value: true || false,
//         Confidence: Number("float"),
//       },
//       EyeDirection: { // EyeDirection
//         Yaw: Number("float"),
//         Pitch: Number("float"),
//         Confidence: Number("float"),
//       },
//     },
//   ],
//   OrientationCorrection: "ROTATE_0" || "ROTATE_90" || "ROTATE_180" || "ROTATE_270",
// };

Example Usage

// This operation detects faces in an image stored in an AWS S3 bucket.
const input = {
"Image": {
"S3Object": {
"Bucket": "mybucket",
"Name": "myphoto"
}
}
};
const command = new DetectFacesCommand(input);
const response = await client.send(command);
/* response ==
{
"FaceDetails": [
{
"BoundingBox": {
"Height": 0.18000000715255737,
"Left": 0.5555555820465088,
"Top": 0.33666667342185974,
"Width": 0.23999999463558197
},
"Confidence": 100,
"Landmarks": [
{
"Type": "eyeLeft",
"X": 0.6394737362861633,
"Y": 0.40819624066352844
},
{
"Type": "eyeRight",
"X": 0.7266660928726196,
"Y": 0.41039225459098816
},
{
"Type": "eyeRight",
"X": 0.6912462115287781,
"Y": 0.44240960478782654
},
{
"Type": "mouthDown",
"X": 0.6306198239326477,
"Y": 0.46700039505958557
},
{
"Type": "mouthUp",
"X": 0.7215608954429626,
"Y": 0.47114261984825134
}
],
"Pose": {
"Pitch": 4.050806522369385,
"Roll": 0.9950747489929199,
"Yaw": 13.693790435791016
},
"Quality": {
"Brightness": 37.60169982910156,
"Sharpness": 80
}
}
],
"OrientationCorrection": "ROTATE_0"
}
*\/
// example id: to-detect-faces-in-an-image-1481841782793
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
JavaScriptLn 1, Col 1
Errors: 0 Warnings: 0

DetectFacesCommand Input

See DetectFacesCommandInput for more details

Parameter
Type
Description
Image
Required
Image | undefined

The input image as base64-encoded bytes or an S3 object. If you use the AWS CLI to call Amazon Rekognition operations, passing base64-encoded image bytes is not supported.

If you are using an AWS SDK to call Amazon Rekognition, you might not need to base64-encode image bytes passed using the Bytes field. For more information, see Images in the Amazon Rekognition developer guide.

Attributes
Attribute[] | undefined

An array of facial attributes you want to be returned. A DEFAULT subset of facial attributes - BoundingBox, Confidence, Pose, Quality, and Landmarks - will always be returned. You can request for specific facial attributes (in addition to the default list) - by using ["DEFAULT", "FACE_OCCLUDED"] or just ["FACE_OCCLUDED"]. You can request for all facial attributes by using ["ALL"]. Requesting more attributes may increase response time.

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

Note that while the FaceOccluded and EyeDirection attributes are supported when using DetectFaces, they aren't supported when analyzing videos with StartFaceDetection and GetFaceDetection.

DetectFacesCommand Output

See DetectFacesCommandOutput for details

Parameter
Type
Description
$metadata
Required
ResponseMetadata
Metadata pertaining to this request.
FaceDetails
FaceDetail[] | undefined

Details of each face found in the image.

OrientationCorrection
OrientationCorrection | undefined

The value of OrientationCorrection is always null.

If the input image is in .jpeg format, it might contain exchangeable image file format (Exif) metadata that includes the image's orientation. Amazon Rekognition uses this orientation information to perform image correction. The bounding box coordinates are translated to represent object locations after the orientation information in the Exif metadata is used to correct the image orientation. Images in .png format don't contain Exif metadata.

Amazon Rekognition doesn’t perform image correction for images in .png format and .jpeg images without orientation information in the image Exif metadata. The bounding box coordinates aren't translated and represent the object locations before the image is rotated.

Throws

Name
Fault
Details
AccessDeniedException
client

You are not authorized to perform the action.

ImageTooLargeException
client

The input image size exceeds the allowed limit. If you are calling DetectProtectiveEquipment, the image size or resolution exceeds the allowed limit. For more information, see Guidelines and quotas in Amazon Rekognition in the Amazon Rekognition Developer Guide.

InternalServerError
server

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

InvalidImageFormatException
client

The provided image format is not supported.

InvalidParameterException
client

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

InvalidS3ObjectException
client

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

ProvisionedThroughputExceededException
client

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

ThrottlingException
server

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

RekognitionServiceException
Base exception class for all service exceptions from Rekognition service.