Spoof Detection
Active Spoof
Active spoof works by observing the geometry and perspective of a face as it moves closer to a camera. Active spoof requires two input images, one far and one close, and is an involved process. Therefore, please be sure to consult the sample code for a demonstration of proper usage.
- SDK.check_spoof_image_face_size(self: tfsdk.SDK, tf_image: tfsdk.TFImage, face_box_and_landmarks: tfsdk.FaceBoxAndLandmarks, active_spoof_state: tfsdk.ACTIVESPOOFSTAGE) tfsdk.ERRORCODE
Ensures that the face size meets the requirements for active spoof. Must check function return value! Active spoof works by analyzing the way a persons face changes as they move closer to a camera. The active spoof solution therefore expects the face a certain distance from the camera. In the far image, the face should be about 18 inches from the camera, while in the near image, the face should be 7-8 inches from the camera. This function must be called before calling
tfsdk.SDK.detect_active_spoof()
.- Parameters:
tf_image - The input
tfsdk.TFImage
, returned bytfsdk.SDK.preprocess_image()
.face_box_and_landmarks - The face on which to run active spoof detection.
active_spoof_state - The stage of the image, either near stage or far stage.
- Returns:
tfsdk.ERRORCODE
- The error code. IfERRORCODE.NO_ERROR
is returned, then the image is eligible for active spoof detection. IfERRORCODE.FACE_TOO_CLOSE
orERRORCODE.FACE_TOO_FAR
is returned, the image is not eligible for active spoof detection.
- SDK.detect_active_spoof(self: tfsdk.SDK, near_face_landmarks: Annotated[List[tfsdk.Point], FixedSize(106)], far_face_landmarks: Annotated[List[tfsdk.Point], FixedSize(106)]) Tuple[tfsdk.ERRORCODE, float, tfsdk.SPOOFLABEL]
Detect if there is a presentation attack attempt. Must call
tfsdk.SDK.check_spoof_image_face_size()
on both input faces before calling this function.- Parameters:
near_face_landmarks - The face landmarks of the near face, obtained by calling
tfsdk.SDK.get_face_landmarks()
.far_face_landmarks - The face landmarks of the far face, obtained by calling
tfsdk.SDK.get_face_landmarks()
.
- Returns:
tfsdk.ERRORCODE
- The error code.float - The output spoof score. If the spoof score is above the threshold, then it is classified as a real face. If the spoof score is below the threshold, then it is classified as a fake face.
tfsdk.SPOOFLABEL
- The predicted spoof result, using a spoofScore threshold of 1.05.
- class tfsdk.ACTIVESPOOFSTAGE
Members:
NEAR : Near image.
FAR : Far image.
- class tfsdk.SPOOFLABEL
Members:
FAKE : The image may be an attempted spoof.
REAL : The face image is real.
Passive Spoof
Passive spoof is meant to be used for selfie-style images from smartphones or from laptop webcams, and should not be used with CCTV cameras / cameras at a distance. Unlike active spoof which requires two input images (one close and one far), passive spoof requires only a single input image. This being said, there are still strict requirements for said input image:
Face must be at least 100 pixels in height. Face height must also be between 0.323 and 0.55 of the total image height.
The face must be centered vertically and horizontally within the frame for portrait images. Landscape images are more permissive for horizontal centering as a portrait region is cropped around the face.
The face must have neutral yaw, pitch, and roll, and must be facing the camera directly.
The eyes must be open.
User must not be wearing a mask.
The image must not be overly bright or dark.
If any of the above criteria are not met, the method will return an error code. It is therefore imperative to check the return value of the function. Please consult the sample code for proper usage of this method. The sample code also demonstrates how to draw an oval of the correct size, prompting the user to place their face in the oval for easy capture of a conforming image. We advise running this method on the front end so that immediate feedback can be provided to the user until they submit a conforming image. We also advise running multiple images through the spoof detector (4-6) and then taking the average result.
- SDK.detect_spoof(*args, **kwargs)
Overloaded function.
detect_spoof(self: tfsdk.SDK, tf_image: tfsdk.TFImage, face_box_and_landmarks: tfsdk.FaceBoxAndLandmarks, threshold: float = 0.75) -> Tuple[tfsdk.ERRORCODE, tfsdk.SPOOFLABEL, float]
Detect if there is a spoof attempt. Returns the spoof score. Passive spoof detection only works with “selfie-style”, meaning the face must be up close and take up most of the frame.
- Parameters:
tf_image - The input
tfsdk.TFImage
, returned bytfsdk.SDK.preprocess_image()
.face_box_and_landmarks -
tfsdk.FaceBoxAndLandmarks
returned bytfsdk.SDK.detect_faces()
ortfsdk.SDK.detect_largest_face()
.threshold - The spoof score threshold above which it is considered a real image (default = 0.75).
- Returns:
tfsdk.ERRORCODE
- The error code.tfsdk.SPOOFLABEL
- The results for the face image.float - The probability that the image is a spoof attempt (1 indicates real image, 0 indicates spoof attempt).
detect_spoof(self: tfsdk.SDK, tf_image: tfsdk.TFImage, face_box_and_landmarks: tfsdk.FaceBoxAndLandmarks, head_orientation: tfsdk.HeadOrientation, blink_state: tfsdk.BlinkState, mask_label: tfsdk.MASKLABEL, threshold: float = 0.75) -> Tuple[tfsdk.ERRORCODE, tfsdk.SPOOFLABEL, float]
Detect if there is a spoof attempt. Returns the spoof score. Passive spoof detection only works with “selfie-style”, meaning the face must be up close and take up most of the frame.
- Parameters:
tf_image - The input
tfsdk.TFImage
, returned bytfsdk.SDK.preprocess_image()
.face_box_and_landmarks -
tfsdk.FaceBoxAndLandmarks
returned bytfsdk.SDK.detect_faces()
ortfsdk.SDK.detect_largest_face()
.head_orientation - The head orientation, returned by
tfsdk.SDK.estimate_head_orientation()
.blink_state - The output of the blink prediction, as returned by
tfsdk.SDK.blink_state()
.mask_label - The predicted MaskLabel for face image, as returned by
tfsdk.SDK.detect_mask()
.threshold - The spoof score threshold above which it is considered a real image (default = 0.75).
- Returns:
tfsdk.ERRORCODE
- The error code.tfsdk.SPOOFLABEL
- The results for the face image.float - The probability that the image is a spoof attempt (1 indicates real image, 0 indicates spoof attempt).
Below are two examples of conforming images, one landscape, and one portrait:
Below are four examples of non-conforming images:
Face too far:
Face too close:
Face yaw angle too extreme:
Face roll angle too extreme:
Image too bright: