- Navigation GuideYou are on a Command (operation) page with structural examples. Use the navigation breadcrumb if you would like to return to the Client landing page.
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
DetectFacesCommand Input
Parameter | Type | Description |
---|
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 |
Attributes | Attribute[] | undefined | An array of facial attributes you want to be returned. A If you provide both, Note that while the FaceOccluded and EyeDirection attributes are supported when using |
DetectFacesCommand Output
Parameter | Type | Description |
---|
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 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 |
---|
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. |