Skip to main content
Version: 3.16.0

Liveness Estimation

In this section you'll learn how to integrate Liveness Estimator to your C++ project.

2D RGB Liveness Estimation (C++)

1. Creating a Liveness Estimator

1.1. To create a Liveness Estimator, follow steps 1-3 described in Creating a Processing Block and specify the value "LIVENESS_ESTIMATOR" for the "unit_type" key. When creating a Liveness Estimator, you can leave out the value for the "model_path" key or pass an empty string "".

configCtx["unit_type"] = "LIVENESS_ESTIMATOR";

// optional
configCtx["capturer_config"] = "common_capturer_uld_fda.xml";
configCtx["liveness_config"] = "liveness_2d_estimator_v3.xml";

1.2. Create a Liveness Estimator Processing Block:

pbio::ProcessingBlock livenessEstimator = service->createProcessingBlock(configCtx);

2. Liveness Estimation

2.1. Create a Context container ioData for input-output data using the createContext() method:

auto ioData = service->createContext();

2.2. Create a Context container imgCtx with RGB-image following the steps described on Creating a Context container with RGB-image.

2.3. Put input image to the input-output data container:

ioData["image"] = imgCtx;

2.4. Call the livenessEstimator and pass the context with source image ioData:

livenessEstimator(ioData);

Accurate estimation requires only one person's face in the frame, looking at the camera, otherwise the status "MULTIPLE_FACE_FRAMED" will be returned.

If multiple faces are captured, only one of them (order is not guaranteed) will be processed.

The result of calling livenessEstimator() will be appended to ioData container. The format of the output data is presented as a list of objects with the "objects" key. Each object in the list has the "class" key with the "face" value.

The "liveness" key contains a Context with 2 elements:

  • "value" key contains a value of type string that matches one of the pbio::Liveness2DEstimator::Liveness state
  • "confidence" key contains a number of type double in a range of [0,1]
/*
{
"objects": [{ "id": {"type": "long", "minimum": 0}
"class": "face",
"liveness": {
"value": {
"enum": ["REAL", "FAKE", "FACE_NOT_FULLY_FRAMED", "MULTIPLE_FACE_FRAMED",
"FACE_TURNED_RIGHT", "FACE_TURNED_LEFT", "FACE_TURNED_UP", "FACE_TURNED_DOWN",
"BAD_IMAGE_LIGHTING", "BAD_IMAGE_NOISE", "BAD_IMAGE_BLUR", "BAD_IMAGE_FLARE"]
}
confidence: {"type": "double", "minimum": 0, "maximum": 1}
}
}]
}
*/

3. GPU Acceleration

Liveness Estimator doesn't support GPU acceleration.