Mask Detection and RGB Liveness Detection

Recognition of Faces with Masks

The same EARFaceRecognitionModelType used for face registration should be used for face recognition.

When registering a face without a mask that is to be matched with faces with and without masks, register the face with kEARFaceRecognitionModelType_Regular and kEARFaceRecognitionModelType_MaskOptimized into two separate person stores.

When recognizing a face, first determine if the face is wearing a mask by using mask detection. If the face is masked, recognize it with kEARFaceRecognitionModelType_MaskOptimized and the corresponding person store. If a face does not have a mask, recognize it with kEARFaceRecognitionModelType_Regular and the corresponding person store.

If also registering faces with a mask, register the faces with masks with kEARFaceRecognitionModelType_MaskOptimized into a third, separate person store. When recognizing a face, first determine if the face has a mask using mask detection. If the face does have a mask, recognize it with kEARFaceRecognitionModelType_MaskOptimized and the corresponding person store containing masked faces. If this fails, attempt to recognize it with kEARFaceRecognitionModelType_MaskOptimized and the person store containing unmasked faces.

If a face does not have a mask, recognize it with kEARFaceRecognitionModelType_Regular and the corresponding person store. If this fails, attempt to recognize it with kEARFaceRecognitionModelType_MaskOptimized and the person store containing masked faces.

RGB Liveness Detection

RGB liveness detection is calculated internally within the face detector (EARFaceDetector) as part of the face detection operation. It's only supported on high sensitivity face detectors (kEARFaceDetectionType_HighSensitivity).

RGB liveness detection is disabled by default. To enable it, set the enableLiveness parameter in the face detection configuration object (EARFaceDetectionConfiguration) to true.

Using the EARFaceDetectorDetect API will result in computing both face detection and RGB liveness detection on a single low resolution image. For best results, the EARFaceDetectorDetectHighRes API should be used if both low resolution and high resolution images can be obtained. Low resolution images (e.g. 480p) should be used for face detection while high resolution images (e.g. 1080p) should be used for RGB liveness detection, which improves the RGB liveness detection accuracy.

Detected face info (EARDetectedFace) returned by the face detection operation contains four liveness-related parameters:

Parameters

The face detection configuration object (EARFaceDetectionConfiguration) contains multiple liveness-related parameters. Some parameters are used to define the minimum required image quality of the detected face image for RGB liveness to be evaluated. When the image quality is too low, the RGB liveness value is set to 0.0 and livenessStatus is set to kEARLivenessLowQuality. The following parameters are used as thresholds for low image quality.

Two additional parameters can be configured: liveness_mode and liveness_initial_threshold.

The liveness_mode parameter is used to select the mode used to calculate the liveness response in multi-model setup. The following modes are allowed:

The liveness_initial_threshold parameter is used to short-circuit stage 2 liveness. It ranges from 0.0 to 1.0. Its default value is 0.19.

Additional Info

Improve Accuracy

We recommended you calculate liveness score on multiple consecutive frames (e.g. 10 frames) to confirm that the face is live or fake.

To ensure reliable RGB liveness detection, the following camera settings are recommended.

Sample Code

#include "eArgusKit.h"
 
// Detects as many faces as possible in the image 'pBitmap' and calculate liveness score for each detected face.
// \param pLicense the SDK license
// \param pBitmap the image description
void detect_faces(const EARLicense* pLicense, const EARBitmap* pBitmap, const EARBitmap* pBitmapHighRes)
{
   EARFaceDetectionInitializationConfiguration initConfig;
   //Enable liveness detection as it is disabled by default
   initConfig.enableLiveness = true;
 
   EARFaceDetectionConfiguration config;
   EARFaceDetectionConfigurationInitWithPreset(&config, kEARFaceDetectionConfigurationPreset_Generic);
    
   //Adjust some default liveness parameters
   config.liveness_initial_threshold = 0.25;
   config.liveness_mode = kEARLivenessModeAverage;
 
   //Only HighSensitivity face detector type supports liveness detection
   EARFaceDetectionType FDType = kEARFaceDetectionType_HighSensitivity;
 
   EARFaceDetectorRef pDetector = EARFaceDetectorCreate(pLicense, FDType, &initConfig, 0);
 
   EARDetectedFaceArrayRef pFaces;
 
   pFaces = EARFaceDetectorDetectHighRes(pDetector, pBitmap, pBitmapHighRes, &config);
   for (size_t i = 0; i < EARDetectedFaceArrayGetCount(pFaces); i++) {
      const EARDetectedFace* pFace = EARDetectedFaceArrayGetAtIndex(pFaces, i);
 
      // Process the face data
      ...
   }
 
   EARDetectedFaceArrayDestroy(pFaces);
   EARFaceDetectorDestroy(pDetector);
}

Additional liveness instructions can be found in Panoptes sample documentation, with liveness sample images in panoptes/sample_images directory.

See Also