Face Matching

Matching service is an AI system that allows to compare the similarity between the face in the identity card, the owner's identity card with the face taken directly of the same person.

1. Match photo face on ID card, citizen ID and portrait photo with photo URL input

API:

MethodURL
GEThttps://cloud.computervision.com.vn/api/v2/ekyc/face_matching

Params:

KeyValueDescription
img1https://example.com/card.pngID card photo URL
img2https://example.com/portrait.pngFace photo URL to match
type1portrait/cardData type of image 1, get values: portrait, card
format_typeurlType of data to pass in, receive values: url, file, base64

Demo Python:

import requests
api_key = "YOUR_API_KEY"
api_secret = "YOUR_API_SECRET"
img_card = 'link_url_img_card'
img_portrait = 'link_url_portrait'
response = requests.get("https://cloud.computervision.com.vn/api/v2/ekyc/face_matching?img1=%s&img2=%s&type1=%s&format_type=%s"
% (img_card, img_portrait, 'card', 'url'),
auth=(api_key, api_secret))
print(response.json())

2. Match photo face on ID card, citizen ID and portrait with image file input

API:

MethodURLcontent-type
POSThttps://cloud.computervision.com.vn/api/v2/ekyc/face_matchingmultipart/form-data

Params:

KeyValueDescription
type1portrait/cardData type of image 1, get values: portrait, card
format_typefileType of data to pass in, receive values: url, file, base64

Body:

KeyTypeValueDescription
img1fileexample_card.jpgID photo file
img2fileexample_portrait.jpgFace image file to match

Demo Python:

import requests
api_key = "YOUR_API_KEY"
api_secret = "YOUR_API_SECRET"
img_card_path = '/path/to/your/img_card.jpg'
img_portrait_path = '/path/to/your/img_portrait.jpg'
response = requests.post(
"https://cloud.computervision.com.vn/api/v2/ekyc/face_matching?type1=%s&format_type=%s"
% ('card', 'file'),
auth=(api_key, api_secret),
files={'img1': open(img_card_path, 'rb'), 'img2': open(img_portrait_path, 'rb')})
print(response.json())

3. Match photo face on ID card, citizen ID and portrait with JSON input

API:

MethodURLcontent-type
POSThttps://cloud.computervision.com.vn/api/v2/ekyc/face_matchingapplication/json

Params:

KeyValueDescription
type1portrait/cardData type of image 1, get values: portrait, card
format_typebase64Type of data to pass in, receive values: url, file, base64

Body:

{
"img1": "iVBORw0KGgoAAAANSU...", // string base64 of ID card photo
"img2": "iVBORw0KGgoAAAANSU..." // string base64 of the face image to match
}

Demo Python:

import base64
import io
import requests
from PIL import Image
def get_byte_img(img):
img_byte_arr = io.BytesIO()
img.save(img_byte_arr, format='PNG')
encoded_img = base64.encodebytes(img_byte_arr.getvalue()).decode('ascii')
return encoded_img
api_key = "YOUR_API_KEY"
api_secret = "YOUR_API_SECRET"
img_card_path = '/path/to/your/img_card.jpg'
img_portrait_path = '/path/to/your/img_portrait.jpg'
encode_card = get_byte_img(Image.open(img_card_path))
encode_portrait = get_byte_img(Image.open(img_portrait_path))
response = requests.post(
"https://cloud.computervision.com.vn/api/v2/ekyc/face_matching?type1=%s&format_type=%s"
% ('card', 'base64'),
auth=(api_key, api_secret),
json={'img1' : encode_card, "img2" : encode_portrait})
print(response.json())

4. Response

For ID card face matching service, the response has the following format:

{
"data": {
"matching": string, // Percentage similarity between two input images
"face1": string, // Face ID photo
"face2": string, // Portrait face photo
"face1_score": string, // Confidence of face1
"face2_score": string, // Confidence of face2
"invalidCode": string,
"invalidMessage": string,
"match": string // 1 if percentage matching > 75%, 0 if percentage matching between [65%, 75%], otherwise -1
},
"errorCode": string,
"errorMessage": string
}

Error code table:

CodeMessage
0Success
1The photo does not contain content
2Url is unavailable
3Incorrect image format
4Out of requests
5Incorrect api_key or api_secret
6Incorrect format type

Warning error code table:

CodeMessage
0Successful
1The ID card photo is not existed
2The picture is a photocopy version of the id card
3The ID card photo is suspected of tampering
4The ID card photo does not contain a face
5The portrait photo does not contain a face
6Photo contains more than one face
7Wearing sunglasses
8Wearing a hat
9Wearing a mask
10Photo taken from picture, screen, blurred noise or sign of fraud
11The face in the picture is too small
12The face in the portrait photo is too close to the margin