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
| Name | Type | Description |
|---|---|---|
image1* | String | Base64 encoded binary data of the first image. |
image2* | String | Base64 encoded binary data of the second image. |
| threshold | Integer | The 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_document | Boolean | Whether or not to verify that the image contains an ID card. Note: default value is False. |
| image1_is_document | Boolean | To verify whether image1 contains an ID Card. Note: default value is False. |
| image2_is_document | Boolean | To verify whether image2 contains an ID Card. Note: default value is False. |
Return Values
| Fields | Type | Description |
|---|---|---|
| request_id | String | Unique ID for each request. |
| score | Float | A 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. |
| match | Boolean | A boolean indicating whether the two faces match or not. |
| time_used | Float | Duration. Unit: second |
| error_message | String | This field will not be returned unless the request fails. For more details, please see the following section on error message. |
Error Message
| HTTP Status | Error Message | Description |
|---|---|---|
| 200 | Face comparison successful. | |
| 400 | FACE_NOT_DETECTED | A face was not detected in one or both images. |
| 400 | ID_CARD_NOT_DETECTED: <image> | The image <image> does not contain an ID card. |
| 400 | ID_CARD_DETECTION_ERROR: <image> | An error occurs during ID card detection. |
| 400 | IMAGE_ERROR_UNSUPPORTED_FORMAT: <image> | The image <image> cannot be processed. The file format may not be supported or the file is damaged. |
| 422 | The request contains invalid request schema. |
Response Examples
- 200: Match
- 200: Not Match
- 400: Face Not Detected
- 400: ID Card Not Detected
- 400: ID Card Detection Error
- 400: Unsupported Format
- 422: Unprocessable Entity
{
"request_id": "string",
"score": 99.80358123779297,
"match": true,
"time_used": 2.168225316999724
}
{
"request_id": "string",
"match": false,
"time_used": 0.7945219540001744
}
{
"request_id": "string",
"time_used": 5.193959645926952,
"error_message": "FACE_NOT_DETECTED"
}
{
"request_id": "string",
"time_used": 0.6722503704950213,
"error_message": "ID_CARD_NOT_DETECTED: image2"
}
{
"request_id": "string",
"time_used": 0.6722503704950213,
"error_message": "ID_CARD_DETECTION_ERROR: image2"
}
{
"request_id": "string",
"time_used": 0.00041714590042829514,
"error_message": "IMAGE_ERROR_UNSUPPORTED_FORMAT: image1"
}
{
"detail": [
{
"loc": ["body", "image1"],
"msg": "field required",
"type": "value_error.missing"
}
]
}
Code Examples
- Python
- Nodejs
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,
})
res = requests.post(api, data=data, headers=headers)
print(res.json())
const axios = require("axios");
const api = "https://api.aigen.online/aiface/face-compare/v3";
const headers = {
"x-aigen-key": "<key>",
};
const data = {
image1: "<base64_string>",
image2: "<base64_string>",
threshold: 80,
};
axios
.post(api, data, { headers: headers })
.then((res) => {
console.log(res.data);
})
.catch((err) => {
console.error(err.response.data);
});