Android ultra-simple integration of live detection technology to quickly identify "fake faces"

Android ultra-simple integration of live detection technology to quickly identify "fake faces"

Preface

Have you ever had such concerns, is it really safe to swipe to unlock? If someone impersonates me with my photos or videos, can the phone find out that I am not in front of the camera? Of course. Huawei's HMS ML Kit live detection technology can accurately distinguish real faces and "fake faces". Whether it is a face retake photo, a face video replay, or a face mask, the live detection technology can immediately expose these "fake faces" and make the "fake faces" invisible!
Insert picture description here

Application scenarios

Living body detection technology is usually used before face comparison technology to confirm that the person in front of the camera is a real person instead of someone using a photo or mask to fake it, and then compare whether the current face and the entered face are the same person. Living body detection technology has a wide range of application scenarios in life. For example, when the mobile phone is unlocked, the live detection technology can prevent someone from impersonating themselves to unlock the mobile phone, causing personal information leakage.
Insert picture description here

Or when dealing with financial services, the living body detection technology can be used in the real-name authentication process to first determine the current face is the real face, and then compare the current face with the photo information on the ID card to confirm that the person handling the business is the person on the ID card , Effectively prevent others from posing as themselves and causing property losses.
Insert picture description here

In addition, the HMS ML Kit live body detection technology supports silent live body detection, and it is not necessary for the user to cooperate to determine whether it is a real face and how is it? Is it very convenient? The following editor will show you how to quickly integrate live detection technology.

Development combat

1. Development Preparation

For detailed preparation steps, please refer to the Huawei Developers Alliance:
https://developer.huawei.com/consumer/cn/doc/development/HMS-Guides/ml-process-4
Here are the key development steps.

1.1 Configure Maven warehouse address in project-level gradle

buildscript {
    
    
    repositories {
    
    
             ...
        maven {
    
    url 'https://developer.huawei.com/repo/'}
    }
}
 dependencies {
    
    
                 ...
        classpath 'com.huawei.agconnect:agcp:1.3.1.300'
    }
allprojects {
    
    
    repositories {
    
    
             ...
        maven {
    
    url 'https://developer.huawei.com/repo/'}
    }
}

1.2 Configure SDK dependencies in application-level gradle

 dependencies{
    
    
        // 引入活体检测集合包。
        implementation 'com.huawei.hms:ml-computer-vision-livenessdetection:2.0.2.300'
}

1.3 Add configuration to the file header

apply plugin: 'com.android.application'
apply plugin: 'com.huawei.agconnect'

1.4 Add the following statement to the AndroidManifest.xml file to automatically update the machine learning model to the device

<meta-data 
  android:name="com.huawei.hms.ml.DEPENDENCY" 
  android:value= "livenessdetection"/>

1.5 Apply for camera permission

For the specific steps of camera permission application, please refer to: https://developer.huawei.com/consumer/cn/doc/development/HMSCore-Guides/add-permissions-0000001050040051

2. Code development

2.1 Create a callback for the live detection result 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 live detection instance and start the detection.

MLLivenessCapture capture = MLLivenessCapture.getInstance();
capture.startDetect(activity, callback);

Demo effect

The following demo shows the detection results of the live detection technology when there are real faces and face masks in front of the camera. Is the effect great?
Insert picture description here

Github source code

https://github.com/HMS-Core/hms-ml-demo/blob/master/MLKit-Sample/module-body/src/main/java/com/mlkit/sample/activity/HumanLivenessDetectionActivity.java

For more detailed development guidelines, please refer to the official website of Huawei Developer Alliance

https://developer.huawei.com/consumer/cn/hms/huawei-mlkit


Original link: https://developer.huawei.com/consumer/cn/forum/topicview?tid=0203345286567820416&fid=18
Author: leave leaves

Guess you like

Origin blog.csdn.net/weixin_44708240/article/details/108732119