Skip to main content

Face Compare

Compare between the two images if the person in the image is the same person.

Image Requirements​

Type : JPG (JPEG), PNG
Format : Base64
Size : Must be over 480*480 pixels
Minimum size of face : The bounding size of a detected face should be over than 112 pixels.

POST https://api.aigen.online/aiface/face-compare/v3

Request Parameters​

NameTypeDescription
image1*StringBase64 encoded binary data of the first image.
image2*StringBase64 encoded binary data of the second image.
thresholdIntegerThe similarity threshold [0, 100] determines whether two faces match or not. Setting the threshold to 0 always returns a similarity score.
Note: default value is 80.
verified_documentBooleanWhether or not to verify that the image contains an ID card.
Note: default value is False.
image1_is_documentBooleanTo verify whether image1 contains an ID Card.
Note: default value is False.
image2_is_documentBooleanTo verify whether image2 contains an ID Card.
Note: default value is False.
image1_check_face_qualityBooleanSet to true to check the quality of image1 with the Face Quality service. The result is returned in face_quality.image1.
Note: default value is False. Only the images you enable are sent to Face Quality. If the Face Quality service is unavailable, the request is not rejected and face_quality is omitted from the response.
image2_check_face_qualityBooleanSame as image1_check_face_quality, for image2.
Note: default value is False.
face_quality_thresholdFloatMinimum quality_confidence [0, 1] that an image checked by Face Quality must reach before the comparison runs. The request fails with FACE_QUALITY_TOO_LOW when an image has no face, has more than one face, or scores below this value.
Note: default value is 0.6. Applies only to images with the face quality check enabled.

Return Values​

FieldsTypeDescription
request_idStringUnique ID for each request.
scoreFloatA similarity score [0,100] indicating the similarity of two faces. A higher score indicates a higher possibility that two faces belong to the same person.
Note: if no face is detected within the image uploaded or the two faces do not match each other, this field will not be returned.
matchBooleanA boolean indicating whether the two faces match or not.
time_usedFloatDuration. Unit: second
face_qualityObjectFace Quality result, returned only when image1_check_face_quality or image2_check_face_quality is true and the Face Quality service responded. Contains image1 and/or image2, each with num_faces (Integer, number of faces detected) and quality_confidence (Float [0, 1], higher is better). An image with no detected face is returned as null.
error_messageStringThis field will not be returned unless the request fails. For more details, please see the following section on error message.

Error Message​

HTTP StatusError MessageDescription
200Face comparison successful.
400FACE_NOT_DETECTEDA face was not detected in one or both images.
400FACE_QUALITY_TOO_LOW: <image>The image <image> failed the face quality check: no face, more than one face, or quality_confidence below face_quality_threshold. Multiple images are comma-separated.
400ID_CARD_NOT_DETECTED: <image>The image <image> does not contain an ID card.
400ID_CARD_DETECTION_ERROR: <image>An error occurs during ID card detection.
400IMAGE_ERROR_UNSUPPORTED_FORMAT: <image>The image <image> cannot be processed. The file format may not be supported or the file is damaged.
422The request contains invalid request schema.

Response Examples​

{
"request_id": "string",
"score": 99.80358123779297,
"match": true,
"time_used": 2.168225316999724
}

Code Examples​

import requests
import json

api = "https://api.aigen.online/aiface/face-compare/v3"
headers = {"x-aigen-key": "<key>", "content-type": "application/json"}
data = json.dumps({
"image1": "<base64_string>",
"image2": "<base64_string>",
"threshold": 80,
"image1_check_face_quality": True,
"image2_check_face_quality": True,
"face_quality_threshold": 0.6,
})

res = requests.post(api, data=data, headers=headers)
print(res.json())