Liveness Detection as Standalone Service
See also
Besides the integrated anti-spoofing system that distinguishes a live face from a face image, FindFace Server provides an API-based face liveness detection service liveness-api
.
The liveness-api
service takes a specific number of frames from a provided video fragment and returns the best quality face, along with a decimal liveness result for it, averaged across the taken frames. If configured, the service can also return full-frame and normalized face images and save the detection result in the sf-api
cache, returning detection_id
.
To install and use the liveness-api
service standalone, see liveness installation.
In this section:
Configure liveness-api
To configure the liveness-api
component, do the following:
Create a default
liveness-api.yaml
configuration file (e.g., into the/opt/ffserver/configs
directory).docker run --rm -ti --name liveness-api-cfg \ docker.int.ntl/ntech/universe/liveness-api:ffserver-11.240325 \ --config-template > /opt/ffserver/configs/liveness-api.yaml
You can configure the
liveness-api
parameters according to your needs in the/opt/ffserver/configs/liveness-api.yaml
configuration file. You can find its default contenthere
. Enable liveness recognition in the/opt/ffserver/configs/extraction-api.yaml
configuration file by specifying the extraction model in theface_liveness
section. See Enable Face and Face Attribute Recognition.
When configuring liveness-api
, refer to the following parameters:
Command line flags |
Type |
Description |
---|---|---|
|
value |
Array of attributes to extract. |
|
string |
Path to config file |
|
Output config template and exit. |
|
|
Debug. |
|
|
string |
Extraction API address (default |
|
int |
Extraction API request batch size (default 16). |
|
duration |
extraction-api-timeouts-connect (default 5s). |
|
duration |
extraction-api-timeouts-idle-connection (default 10s). |
|
duration |
extraction-api-timeouts-overall (default 35s). |
|
duration |
extraction-api-timeouts-response-header (default 30s). |
|
int |
JPEG quality of full frames in the |
|
Print help information. |
|
|
float |
Maximum video frames per second (default 60). |
|
int |
Maximum video height in px (default 1080). |
|
float |
Maximum video length in seconds (default 60). |
|
int |
Maximum size of video supplied in request body, bytes. (default 10485760). |
|
int |
Maximum video width in pixels (default 1920) |
|
string |
IP:port to listen on (default |
|
float |
Liveness threshold (default 0.994). |
|
int |
Finish decoding after reaching the specified number of frames (default 30). |
|
string |
Service behavior upon having multiple faces in the video frame: |
|
int |
The minimum number of final frames successfully passed through decoding and liveness extraction. Must be equal or less than |
|
string |
Path to LUA file with processing_script function (default |
|
float |
Proportion of the secondary faces for them to be ignored. |
|
string |
SF API address (default |
|
duration |
sf-api-timeouts-connect (default 5s). |
|
duration |
sf-api-timeouts-idle-connection (default 10s). |
|
duration |
sf-api-timeouts-overall (default 35s). |
|
duration |
sf-api-timeouts-response-header (default 30s). |
The format of environment variable for flag -my-flag
is CFG_MY_FLAG
.
Priority:
Defaults from source code (lowest priority).
Configuration file.
Environment variables.
Command line.
Note
When working with processing_<attribute>.lua
don’t forget to get the appropriate attribute by setting it in the configuration file in the attributes
section.
The default processing_score.lua
file describes the logic of choosing the best face:
function process(candidates)
local best_frame_idx = nil
local best_score = nil
for idx, candidate in pairs(candidates) do
local score = candidate.score
if (best_frame_idx == nil) or (best_score < score) then
best_score = score
best_frame_idx = idx
end
end
return best_frame_idx
end
HTTP API Requests to liveness-api
To interact with the liveness-api
service, use HTTP API requests to http://liveness-api:18301/
.
POST /v1/video-liveness
This method determines liveness by video.
Query string parameters:
return_detection
(required=false
,default=False
): boolean, save the best face in thesf-api
cache and return itsdetection_id
.return_normalized
(required=false
,default=False
): boolean, return the face normalized image in thenormalized
field.return_photo
(required=false
,default=False
): boolean, return the full frame in thephoto
field.
Request Body:
Contains a video file.
Responses with Common Codes:
Code |
Description |
---|---|
200 |
OK. Returns |
400 |
Bad Request. |
405 |
Invalid input. |
406 |
Not Acceptable. |
500 |
Internal Server Error. |
Example
Request
curl -i -X POST \
'127.0.0.1:18301/v1/video-liveness?return_detection=true&return_normalized=true&return_photo=true' \
--header 'Content-Type: video/mp4' \
--data-binary '@/home/my_video.mp4'
Response
HTTP/1.1 200 OK
Content-Type: application/json
{
"alive":true,
"average_liveness":0.9521886,
"best_face":{
"liveness":0.9557304,
"quality":0.91568387,
"bbox":{
"left":138,
"top":172,
"right":363,
"bottom":468
},
"detection_id":"btfiva1o8cjc1k44q1vg",
"photo":"/9j/2wCEAAgGBgcGBQgHBwcJ...",
"normalized":"iVBORw0KGgoAAAANSUU...",
"frame_no":14,
"frame_ts":0.56
}
}