Silent liveness detection is the face liveness detection capability of Huawei HMS Core machine learning service , that is, without the need for the user to cooperate with actions such as opening the mouth, turning the head, blinking, etc. The use process is convenient and the overall experience is better.
Technical principle
The silent live detection capability uses an RGB camera to identify whether the detected object in front of the camera is a real face, or a face remake, a face remake screen, or a face mask through some detailed information such as moiré patterns and paper photo reflections that appear on the screen. Wait for fake face attack. At the same time, the living body data of the silent living body detection capability covers scenes such as lighting, facial accessories, gender, hairstyle, and mask material, and analyzes the macro environment where faces exist, and excludes scenes where faces are obviously impossible.
The model design of the silent live detection capability adopts a lightweight convolution module, and at the same time, the linear calculation of the model is converted into a single convolution or fully connected module in the inference stage through the re-parameterization idea. Model deployment uses the Mindspore-lite inference framework to tailor operators to achieve the ultimate package size, which is more convenient for developers to integrate applications.
Application scenarios
The liveness detection technology is usually applied before the face comparison technology. For example, when the face recognition mobile phone is unlocked, it is first necessary to use the liveness detection technology to determine whether the face that appears in front of the machine is a real face or a fake face, and then compare the current face with the system's existing face. Whether the face entered is the same person, this can prevent someone from impersonating the party to unlock the phone without the party being present, causing serious losses such as personal information leakage.
So, how can we integrate silent live detection capabilities?
Integration steps
1. Development preparation
For detailed steps, please refer to the application development introduction on the official website of Huawei Developer Alliance: https://developer.huawei.com/consumer/cn/doc/development/hiai-Guides/liveness-detection-0000001051386243?ha_source=hms1
Silent liveness detection provides two invocation methods, and you can choose the corresponding invocation method to build the liveness detection service according to your needs.
2. Default scan interface
2.1 Create a silent live detection result callback to obtain the detection result.
private MLLivenessCapture.Callback callback = new MLLivenessCapture.Callback() {
@Override
public void onSuccess(MLLivenessCaptureResult result) {
// 检测成功的处理逻辑,检测结果可能是活体或者非活体。
}
@Override
public void onFailure(int errorCode) {
// 检测未完成,如相机异常CAMERA_ERROR,添加失败的处理逻辑。
}
};
2.2 Create a silent live detection instance and start the detection.
MLLivenessCapture capture = MLLivenessCapture. getInstance();
capture.startDetect(activity, callback);
3. Customize the scan interface
3.1 Create MLLivenessDetectView and load it into Activity layout.
- I. Bind the camera preview interface and set the living body recognition area.
In the camera preview stream, the silent live detection will judge whether the face is not in the middle of the image. In order to improve the pass rate of the living body, it is recommended to place the face frame in the middle of the screen, and the living body recognition area is slightly larger than the drawn face frame. .
- II. Set whether to detect masks.
- III. Set the result callback.
- IV. Load MLLivenessDetectView into Activity.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_liveness_custom_detection);
mPreviewContainer = findViewById(R.id.surface_layout);
// ObtainLLivenessDetectView
mlLivenessDetectView = new MLLivenessDetectView.Builder()
.setContext(this)
//设置是否检测口罩
.setOptions(MLLiveness DetectView.DETECT_MASK)
//设置人脸框相对于MLLivenessDetectView的Rect
.setFaceRect(new Rect(0, 0, 0, 200))
//设置结果回调
.setDetectCallback(new OnMLLivenessDetectCallback() {
@Override
public void onCompleted(MLLivenessCaptureResult result) {
// 静默活体检测完成时的结果回调
}
@Override
public void onError(int error) {
// 活体检测发生错误时的错误码回调
}
@Override
public void onInfo(int infoCode, Bundle bundle) {
// 静默活体检测提示信息回调,可用于界面提示
// if(infoCode==MLLivenessDetectInfo.NO_FACE_WAS_DETECTED){
// 当前没有检测到人脸
// }
// ...
}
@Override
public void onStateChange(int state, Bundle bundle) {
// 静默活体检测状态切换回调
// if(state==MLLivenessDetectStates.START_DETECT_FACE){
// 开始人脸检测
// }
// ...
}
}).build();
mPreviewContainer.addView(mlInteractiveLivenessDetectView);
mlInteractiveLivenessDetectView.onCreate(savedInstanceState);
}
4. Set life process monitoring for MLLivenessDetectView.
@Override
protected void onDestroy() {
super.onDestroy();
mlLivenessDetectView.onDestroy();
}
@Override
protected void onPause() {
super.onPause();
mlLivenessDetectView.onPause();
}
@Override
protected void onResume() {
super.onResume();
mlLivenessDetectView.onResume();
}
@Override
protected void onStart() {
super.onStart();
mlLivenessDetectView.onStart();
}
@Override
protected void onStop() {
super.onStop();
mlLivenessDetectView.onStop();
}
For more information about machine learning services, please visit HUAWEI Developer Alliance official website .
If you encounter problems when integrating the SDK or listing the application on the Huawei AppGallery, you can online bill of lading .
Learn more >>
Visit Huawei Developer Alliance official website
Get development guidance document
Huawei Mobile Services open source warehouse address: GitHub , Gitee
Follow us and know the latest technical information of HMS Core for the first time~
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。