tencent cloud

文档反馈

DetectFaceAttributes

最后更新时间:2023-02-27 15:22:53

1. API Description

Domain name for API request: iai.tencentcloudapi.com.

This API is used to detect the position, attributes, and quality information of a face in the given image. The position information includes (x, y, w, h); the face attributes include gender, age, expression, beauty, glass, hair, mask, and pose (pitch, roll, yaw); and the face quality information includes the overall quality score, sharpness, brightness, and completeness.

The face quality information is mainly used to evaluate the quality of the input face image. When using the Face Recognition service, we recommend evaluating the quality of the input face image first to improve the effects of subsequent processing. Application scenarios of this feature include:

  1. Creating/Adding a person in a group: This is to ensure the quality of the face information to facilitate subsequent processing.

  2. Face search: This is to ensure the quality of the input image to quickly find the corresponding person.

  3. Face verification: This is to ensure the quality of the face information to avoid cases where the verification fails unexpectedly.

  4. Face fusion: This is to ensure the quality of the uploaded face images to improve the fusion effect.

  • This API is an upgrade of DetectFace; specifically:
  1. This API can be used to specify the face attributes that need to be computed and returned, which avoids ineffective computation and reduces time consumption.
  2. This API supports more detailed attribute items and will continue providing new features in the future.
    Use this API for corresponding face detection and attribute analysis.
  • Use the signature algorithm v3 to calculate the signature in the common parameters, that is, set the parameter SignatureMethod to TC3-HMAC-SHA256.
We recommend you to use API Explorer
Try it
API Explorer provides a range of capabilities, including online call, signature authentication, SDK code generation, and API quick search. It enables you to view the request, response, and auto-generated examples.

2. Input Parameters

The following request parameter list only provides API request parameters and some common parameters. For the complete common parameter list, see Common Request Parameters.

Parameter Name Required Type Description
Action Yes String Common Params. The value used for this API: DetectFaceAttributes.
Version Yes String Common Params. The value used for this API: 2020-03-03.
Region No String Common Params. This parameter is not required for this API.
MaxFaceNum No Integer Maximum number of processable faces.
Default value: 1 (i.e., detecting only the face with the largest size in the image). Maximum value: 120.
This parameter is used to control the number of faces in the image to be detected. The smaller the value, the faster the processing.
Image No String Base64-encoded image data, which cannot exceed 5 MB.
The long side cannot exceed 4,000 px for images in JPG format or 2,000 px for images in other formats.
PNG, JPG, JPEG, and BMP images are supported, while GIF images are not.
Url No String Image URL.
The image cannot exceed 5 MB in size after being Base64-encoded.
The long side cannot exceed 4,000 px for images in JPG format or 2,000 px for images in other formats.
Either Url or Image must be provided; if both are provided, only Url will be used.
We recommend storing the image in Tencent Cloud, as a Tencent Cloud URL can guarantee higher download speed and stability.
The download speed and stability of non-Tencent Cloud URLs may be low.
PNG, JPG, JPEG, and BMP images are supported, while GIF images are not.
FaceAttributesType No String Whether to return attributes such as age, gender, and emotion.
Valid values (case-insensitive): None, Age, Beauty, Emotion, Eye, Eyebrow, Gender, Hair, Hat, Headpose, Mask, Mouth, Moustache, Nose, Shape, Skin, Smile.

None indicates that no attributes need to be returned, which is the default value; that is, if the FaceAttributesType attribute is empty, the values of all attributes will be 0.
You need to combine the attributes into a string and separate them by comma. The sequence of the attributes is not limited.
For more information on the attributes, see the output parameters as described below.
The face attribute information of up to 5 largest faces in the image will be returned, and AttributesInfo of the 6th and rest faces is meaningless.
NeedRotateDetection No Integer Whether to enable the support for rotated image recognition. 0: no; 1: yes. Default value: 0. When the face in the image is rotated and the image has no EXIF information, if this parameter is not enabled, the face in the image cannot be correctly detected and recognized. If you are sure that the input image contains EXIF information or the face in the image is not rotated, do not enable this parameter, as the overall time consumption may increase by hundreds of milliseconds after it is enabled.
FaceModelVersion No String Algorithm model version used by the Face Recognition service. You can enter only 3.0 for this API.

3. Output Parameters

Parameter Name Type Description
ImageWidth Integer Width of requested image.
ImageHeight Integer Height of requested image.
FaceDetailInfos Array of FaceDetailInfo Face information list.
FaceModelVersion String Algorithm model version used for face recognition.
RequestId String The unique request ID, which is returned for each request. RequestId is required for locating a problem.

4. Example

Example1 Detecting faces and analyzing attributes

Input Example

POST / HTTP/1.1
Host: iai.tencentcloudapi.com
Content-Type: application/json
X-TC-Action: DetectFaceAttributes
<Common request parameters>

{
    "Url": "http://test.image.myqcloud.com/testA.jpg",
    "FaceAttributesType": "eye"
}

Output Example

{
    "Response": {
        "ImageWidth": 550,
        "ImageHeight": 366,
        "FaceModelVersion": "3.0",
        "FaceDetailInfos": [
            {
                "FaceRect": {
                    "X": 375,
                    "Y": 37,
                    "Width": 63,
                    "Height": 82
                },
                "FaceDetailAttributesInfo": {
                    "Age": 0,
                    "Beauty": 0,
                    "Emotion": {
                        "Type": 0,
                        "Probability": 0
                    },
                    "Eye": {
                        "Glass": {
                            "Type": 0,
                            "Probability": 0.99936753511429
                        },
                        "EyeOpen": {
                            "Type": 0,
                            "Probability": 0.99949336051941
                        },
                        "EyelidType": {
                            "Type": 1,
                            "Probability": 0.75467920303345
                        },
                        "EyeSize": {
                            "Type": 2,
                            "Probability": 0.59152442216873
                        }
                    },
                    "Eyebrow": {
                        "EyebrowDensity": {
                            "Type": 0,
                            "Probability": 0
                        },
                        "EyebrowCurve": {
                            "Type": 0,
                            "Probability": 0
                        },
                        "EyebrowLength": {
                            "Type": 0,
                            "Probability": 0
                        }
                    },
                    "Gender": {
                        "Type": 0,
                        "Probability": 0
                    },
                    "Hair": {
                        "Length": {
                            "Type": 0,
                            "Probability": 0
                        },
                        "Bang": {
                            "Type": 0,
                            "Probability": 0
                        },
                        "Color": {
                            "Type": 0,
                            "Probability": 0
                        }
                    },
                    "Hat": {
                        "Style": {
                            "Type": 0,
                            "Probability": 0
                        },
                        "Color": {
                            "Type": 0,
                            "Probability": 0
                        }
                    },
                    "HeadPose": {
                        "Pitch": 0,
                        "Yaw": 0,
                        "Roll": 0
                    },
                    "Mask": {
                        "Type": 0,
                        "Probability": 0
                    },
                    "Mouth": {
                        "MouthOpen": {
                            "Type": 0,
                            "Probability": 0
                        }
                    },
                    "Moustache": {
                        "Type": 0,
                        "Probability": 0
                    },
                    "Nose": {
                        "Type": 2,
                        "Probability": 0.75233882665634
                    },
                    "Shape": {
                        "Type": 0,
                        "Probability": 0
                    },
                    "Skin": {
                        "Type": 0,
                        "Probability": 0
                    },
                    "Smile": 0
                }
            }
        ],
        "RequestId": "b2c154b9-4620-4d37-8fd1-f6af3748f998"
    }
}

5. Developer Resources

SDK

TencentCloud API 3.0 integrates SDKs that support various programming languages to make it easier for you to call APIs.

Command Line Interface

6. Error Code

The following only lists the error codes related to the API business logic. For other error codes, see Common Error Codes.

Error Code Description
AuthFailure.InvalidAuthorization Authentication failed.
FailedOperation.FaceSizeTooSmall The face frame size is smaller than the MinFaceSize value, and the face is filtered out.
FailedOperation.ImageDecodeFailed Image decoding failed.
FailedOperation.ImageDownloadError An error occurred while downloading the image.
FailedOperation.ImageResolutionExceed The image resolution is too high.
FailedOperation.ImageResolutionTooSmall The image short edge resolution is smaller than 64.
FailedOperation.ImageSizeExceed The size of the Base64-encoded image cannot exceed 5 MB.
FailedOperation.RequestLimitExceeded The request frequency exceeds the limit.
FailedOperation.RequestTimeout The backend service timed out.
FailedOperation.RpcFail The RPC call failed.
FailedOperation.ServerError The algorithm service is exceptional. Please retry.
FailedOperation.UnKnowError An internal error occurred.
InternalError Internal error.
InvalidParameter.InvalidParameter Invalid parameter.
InvalidParameterValue.FaceModelVersionIllegal The algorithm model version is invalid.
InvalidParameterValue.ImageEmpty Empty image.
InvalidParameterValue.NoFaceInPhoto There are no faces in the image.
InvalidParameterValue.UrlIllegal Invalid URL format.
LimitExceeded.ErrorFaceNumExceed The number of faces exceeds the limit.
MissingParameter.ErrorParameterEmpty A required parameter is empty.
ResourceUnavailable.Delivering The resource is being shipped.
ResourceUnavailable.Freeze The account is frozen.
ResourceUnavailable.InArrears The account is in arrears.
ResourceUnavailable.NotExist The billing status is unknown. Please check whether the service has been activated in the console.
ResourceUnavailable.Recover The resource has been repossessed.
ResourceUnavailable.StopUsing The service has been suspended for the account.
ResourceUnavailable.UnknownStatus The billing status is unknown.
ResourcesSoldOut.ChargeStatusException The billing status is exceptional.
UnsupportedOperation.UnknowMethod Unknown method name.
联系我们

联系我们,为您的业务提供专属服务。

技术支持

如果你想寻求进一步的帮助,通过工单与我们进行联络。我们提供7x24的工单服务。

7x24 电话支持