Face Validation
Validate selfie images with Incode API
Introduction
There are 2 validations related to a face (or selfie image):
- Liveness validation. This one is performed as soon as you add a selfie image to a session via the endpoint
/omni/add/face/third-party?imageType=selfie
. - Face Match validation. This validation compares the selfie image against the face that appears on the ID. This one is performed when you call the endpoint
/omni/process/face?imageType=selfie
For this one to work, the session requires to have an ID already in the session(like we did in previous step).
You can see the information for the above endpoints in the API reference. See:
Requirements
x-api-key
header is required with it's value set to your Api Keyapi-version
header is required and must be set to 1.0X-Incode-Hardware-Id
header is required with it's value set to our Session Token. Obtained when we started our onboarding session.- Always call the endpoints in the mentioned order ( add face -> process face)
- Images need to be provided as a base64 encoded string
Image Requirements
- Images should be at least 1000 pixels on one dimension, width or height.
- Make sure the request doesn't exceed the 10mb mentioned in the limitations of the API
Sample Code
Add face
curl --location 'https://demo-api.incodesmile.com/omni/add/face/third-party?imageType=selfie' \
--header 'Content-Type: application/json' \
--header 'api-version: 1.0' \
--header 'x-api-key: <your_api_key>' \
--header 'X-Incode-Hardware-Id: <your_session_token>' \
--data '{
"base64Image": ""
}'
const axios = require('axios');
const fs = require('fs');
// Read your image file and encode as base64
const imageFilePath = 'path/to/your/image.jpg';
const base64 = fs.readFileSync(imageFilePath, { encoding: 'base64' });
const data = JSON.stringify({
base64Image: base64
});
const config = {
method: 'post',
url: 'https://demo-api.incodesmile.com/omni/add/face/third-party?imageType=selfie',
headers: {
'Content-Type': 'application/json',
'api-version': '1.0',
'x-api-key': '<your_api_key>',
'X-Incode-Hardware-Id': '<your_session_token>'
},
data : data
};
axios(config).then(function (response) {
console.log(response.data);
});
var client = HttpClient.newHttpClient();
// Read your image file and encode as base64
Path imagePath = Path.of("path/to/your/image.jpg");
String base64 = Base64.getEncoder().encodeToString(Files.readAllBytes(imagePath));
var request = HttpRequest.newBuilder()
.uri(URI.create("https://demo-api.incodesmile.com/omni/add/face/third-party?imageType=selfie"))
.header("Content-Type", "application/json")
.header("api-version", "1.0")
.header("x-api-key", "<your_api_key>")
.header("X-Incode-Hardware-Id", "<your_session_token>")
.POST(BodyPublishers.ofString("{\"base64Image\":\"" + base64 + "\"}"))
.build();
var response = client.send(request, BodyHandlers.ofString());
System.out.println(response.body());
using var client = new HttpClient();
// Read your image file and encode as base64
var imageFilePath = "path/to/your/image.jpg";
var base64 = Convert.ToBase64String(File.ReadAllBytes(imageFilePath));
var json = "{\"base64Image\":\"" + base64 + "\"}";
var content = new StringContent(json, Encoding.UTF8, "application/json");
client.DefaultRequestHeaders.Add("api-version", "1.0");
client.DefaultRequestHeaders.Add("x-api-key", "<your_api_key>");
client.DefaultRequestHeaders.Add("X-Incode-Hardware-Id", "<your_session_token>");
var response = await client.PostAsync("https://demo-api.incodesmile.com/omni/add/face/third-party?imageType=selfie", content);
var responseString = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseString);
import requests
import base64
# Read your image file and encode as base64
image_file_path = 'path/to/your/image.jpg'
with open(image_file_path, "rb") as image_file:
base64 = base64.b64encode(image_file.read()).decode('utf-8')
url = "https://demo-api.incodesmile.com/omni/add/face/third-party?imageType=selfie"
payload = {
"base64Image": base64
}
headers = {
'Content-Type': 'application/json',
'api-version': '1.0',
'x-api-key': '<your_api_key>',
'X-Incode-Hardware-Id': '<your_session_token>'
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)
After adding a face, you can find the liveness score obtained from it in the dashboard. You can see more details about this request / response here: Add face/Selfie image
Process face
curl --location 'https://demo-api.incodesmile.com/omni/process/face?imageType=selfie' \
--header 'Content-Type: application/json' \
--header 'api-version: 1.0' \
--header 'x-api-key: <your_api_key>' \
--header 'X-Incode-Hardware-Id: <your_session_token>' \
--data '{}'
const axios = require('axios');
const data = JSON.stringify({});
const config = {
method: 'post',
url: 'https://demo-api.incodesmile.com/omni/process/face?imageType=selfie',
headers: {
'Content-Type': 'application/json',
'api-version': '1.0',
'x-api-key': '<your_api_key>',
'X-Incode-Hardware-Id': '<your_session_token>'
},
data : data
};
axios(config).then(function (response) {
console.log(response.data);
});
var client = HttpClient.newHttpClient();
var request = HttpRequest.newBuilder()
.uri(URI.create("https://demo-api.incodesmile.com/omni/process/face?imageType=selfie"))
.header("Content-Type", "application/json")
.header("api-version", "1.0")
.header("x-api-key", "<your_api_key>")
.header("X-Incode-Hardware-Id", "<your_session_token>")
.POST(BodyPublishers.ofString("{}"))
.build();
var response = client.send(request, BodyHandlers.ofString());
System.out.println(response.body());
using var client = new HttpClient();
var json = "{}";
var content = new StringContent(json, Encoding.UTF8, "application/json");
client.DefaultRequestHeaders.Add("api-version", "1.0");
client.DefaultRequestHeaders.Add("x-api-key", "<your_api_key>");
client.DefaultRequestHeaders.Add("X-Incode-Hardware-Id", "<your_session_token>");
var response = await client.PostAsync("https://demo-api.incodesmile.com/omni/process/face?imageType=selfie", content);
var responseString = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseString);
import requests
url = "https://demo-api.incodesmile.com/omni/process/face?imageType=selfie"
payload = {}
headers = {
'Content-Type': 'application/json',
'api-version': '1.0',
'x-api-key': '<your_api_key>',
'X-Incode-Hardware-Id': '<your_session_token>'
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)
After processing the face, you can find the face-match score obtained from it in the dashboard. You can see more details about this request / response here: Process face
Updated about 2 months ago
What’s Next