当前位置:网站首页>刷脸认证如何实现人脸又快又准完成校验?
刷脸认证如何实现人脸又快又准完成校验?
2022-06-09 17:14:00 【nginx】
HMS Core机器学习服务(ML Kit)的人脸比对和活体检测能力能够快速捕捉人脸,通过识别并提取模板中的人脸特征,不需要用户配合做动作就可以判断是真实人脸,还是人脸攻击,同时将模板人像和人脸进行高精度比对,输出相似度值,进而判断两者是否为同一个人。
基于此,开发者可以快速构建人脸检测能力,比如在金融类App中,比对用户身份证照片和人脸检测结果,判断用户信息真实性,可提供快速安全的身份核验流程,适用于互联网远程开户、刷脸支付等金融业务。在办公App中,可采取刷脸考勤,识别是否为本人,有效防止代打卡等行为。
效果展示

从效果展示图来看,活体检测几秒钟就可以完成精准识别手机上的假照片。
开发步骤
开发准备
- 在AppGallery Connect中配置相关信息,具体开发准备可以参考文档。
- 配置HMS Core SDK的Maven仓地址。

添加AppGallery Connect插件以及Maven代码库。
在“allprojects”>“repositories”里面配置HMS Core SDK的Maven仓地址。
在“buildscript”>“repositories”里面配置HMS Core SDK的Maven仓地址。
allprojects {repositories {google()jcenter()maven {url 'https://developer.huawei.com/repo/'}}}
在“buildscript”>“dependencies”里面增加AppGallery Connect插件配置。
buildscript {repositories {google()jcenter()maven {url 'https://developer.huawei.com/repo/'}}}
人脸比对功能开发
buildscript{dependencies {classpath 'com.huawei.agconnect:agcp:1.3.1.300'}}
- 创建人脸比对检测器实例。
MLFaceVerificationAnalyzer analyzer = MLFaceVerificationAnalyzerFactory.getInstance().getFaceVerificationAnalyzer();
- 通过android.graphics.Bitmap创建MLFrame对象用于设置模版图片,支持的图片格式包括:JPG、JPEG、PNG、BMP。
// 通过bitmap创建MLFrameMLFrame templateFrame = MLFrame.fromBitmap(bitmap);
- 设置人脸比对模版图片。如果模板中无人脸,则表示模板设置失败,保持该实例上一次设置的模板不变。
List<MLFaceTemplateResult> results = analyzer.setTemplateFace(templateFrame);for (int i = 0; i < results.size(); i++) {// 处理模板图片识别结果}
- 通过android.graphics.Bitmap创建MLFrame对象用于设置比对图片。支持的图片格式包括:JPG、JPEG、PNG、BMP。
// 通过bitmap创建MLFrameMLFrame compareFrame = MLFrame.fromBitmap(bitmap);
- 调用同步或异步方法进行人脸比对。检测结果主要包括比对图片中检测到的人脸信息、检测到的人脸信息与模板人脸是同一个人的置信度。详细信息请参见MLFaceVerificationResult。
·同步方法示例代码:
Task<List<MLFaceVerificationResult>> task = analyzer.asyncAnalyseFrame(compareFrame);task.addOnSuccessListener(new OnSuccessListener<List<MLFaceVerificationResult>>() {@Overridepublic void onSuccess(List<MLFaceVerificationResult> results) {// 检测成功}}).addOnFailureListener(new OnFailureListener() {@Overridepublic void onFailure(Exception e) {// 检测失败}});
SparseArray<MLFaceVerificationResult> results = analyzer.analyseFrame(compareFrame);for (int i = 0; i < results.size(); i++) {// 检测结果处理}
- 检测完成,停止分析器,释放检测资源。
活体检测功能开发
if (analyzer != null) {analyzer.stop();}
默认扫描界面
- 创建静默活体检测结果回调,用于获取检测结果。
private MLLivenessCapture.Callback callback = new MLLivenessCapture.Callback() {@Overridepublic void onSuccess(MLLivenessCaptureResult result) {//检测成功的处理逻辑,检测结果可能是活体或者非活体。}@Overridepublic void onFailure(int errorCode) {//检测未完成,如相机异常CAMERA_ERROR,添加失败的处理逻辑。}};
- 创建静默活体检测实例,启动检测。
了解更多详情>>
MLLivenessCapture capture = MLLivenessCapture.getInstance();capture.startDetect(activity, callback);
访问华为开发者联盟官网
获取开发指导文档
华为移动服务开源仓库地址:GitHub、Gitee
关注我们,第一时间了解 HMS Core 最新技术资讯~
边栏推荐
- slurm program running without multiprocess instead run individually
- 图解 Google V8 # 06:原型链:V8是如何实现对象继承的?
- 【GAMES101】作业1--MVP(模型、视图、投影)变换
- 14届数独-真题标准数独-Day 6-20220121(补)
- How about opening an account with tongdaxin? Is it safe to open an account?
- pta7-5新浪微博热门话题
- Interview questions - Supplement of Huawei computer test knowledge points
- 问题 D: 马走日
- go-zero 微服务实战系列(二、服务拆分)
- Pyepics -- alarm: respond when a PV is out of range
猜你喜欢
随机推荐
c语言解决爬楼梯问题
About not adding mysql data. DLL
Sbio | Chenyun group of Zhejiang University Review on the interaction mechanism between bacteria and fungi in agriculture
华为云零代码开发图片压缩工具
ARM指令集复习 | 基本指令用法
Small program startup performance optimization practice
CREMB Pro 后台子管理员 403 问题分析
c語言解决爬樓梯問題
Android caching mechanism lrucache
R 安装/更新 package 报错:failed to lock directory ‘/home/anaconda3/envs/R4.1.2/lib/R/library’
Scientific research practice | the visualization and visual analysis laboratory of Peking University enrolls summer interns and graduate students
Construction of sheep (rare species) bsgenome reference genome
Real topic of the 13th provincial competition of the Blue Bridge Cup in 2022 - block painting
Pyepics -- alarm: respond when a PV is out of range
音频 3A 处理实践,让你的应用更「动听」
JLINK RTT 能打开却不能在桌面显示问题和BIN文件输出注意事项
JLINK RTT printing floating point numbers and negative numbers
【嵌入式工程师·单片机】① 基础概念 之 单片机
虚拟存储机制
Pyepics array -- 4








