当前位置:网站首页>刷脸认证如何实现人脸又快又准完成校验?
刷脸认证如何实现人脸又快又准完成校验?
2022-06-10 18:54:00 【HMS Core】
互联网飞速发展的今天,各种App的验证方法也越来越方便用户,从一开始的密码输入,到后来的指纹解锁,演变成如今的刷脸认证。刷个脸,就可以解锁设备、在线/线下支付、通过门禁、快速检票等。与此同时也伴随了很多安全问题,首要就是如何判断用户的真实性。
HMS Core机器学习服务(ML Kit)的人脸比对和活体检测能力能够快速捕捉人脸,通过识别并提取模板中的人脸特征,不需要用户配合做动作就可以判断是真实人脸,还是人脸攻击,同时将模板人像和人脸进行高精度比对,输出相似度值,进而判断两者是否为同一个人。
基于此,开发者可以快速构建人脸检测能力,比如在金融类App中,比对用户身份证照片和人脸检测结果,判断用户信息真实性,可提供快速安全的身份核验流程,适用于互联网远程开户、刷脸支付等金融业务。在办公App中,可采取刷脸考勤,识别是否为本人,有效防止代打卡等行为。
效果展示

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

添加AppGallery Connect插件以及Maven代码库。
在“allprojects”>“repositories”里面配置HMS Core SDK的Maven仓地址。
allprojects { repositories { google() jcenter() maven {url 'https://developer.huawei.com/repo/'} } }在“buildscript”>“repositories”里面配置HMS Core SDK的Maven仓地址。
buildscript { repositories { google() jcenter() maven {url 'https://developer.huawei.com/repo/'} } }在“buildscript”>“dependencies”里面增加AppGallery Connect插件配置。
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>>() { @Override public void onSuccess(List<MLFaceVerificationResult> results) { // 检测成功 }}).addOnFailureListener(new OnFailureListener() { @Override public 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() { @Override public void onSuccess(MLLivenessCaptureResult result) { //检测成功的处理逻辑,检测结果可能是活体或者非活体。 } @Override public void onFailure(int errorCode) { //检测未完成,如相机异常CAMERA_ERROR,添加失败的处理逻辑。 }};- 创建静默活体检测实例,启动检测。
MLLivenessCapture capture = MLLivenessCapture.getInstance();capture.startDetect(activity, callback);了解更多详情>>
访问华为开发者联盟官网
获取开发指导文档
华为移动服务开源仓库地址:GitHub、Gitee
关注我们,第一时间了解 HMS Core 最新技术资讯~
边栏推荐
- Solving Bob's survival problem by trilogy routine
- 【C语言进阶】数据的存储【下篇】【万字总结】
- Before we learn about high-performance computing, let's take a look at its history
- TiDB - 快速入门,集群搭建
- Complete knapsack problem and optimization tips
- 批量检测不同url的指定端口(py脚本)
- 恭喜 | 医学院那洁课题组通过多组学分析揭示JUNB在体外分化人造血祖细胞过程中的功能
- Mongodb index unique
- VR全景作品中各式各样的嵌入功能是如何做到的?
- 100003 words, take you to decrypt the system architecture under the double 11 and 618 e-commerce promotion scenarios
猜你喜欢

大学生毕业季找房,VR全景看房帮你线上筛选

深入理解LightGBM

2022.05.23 (lc_300_longest increment subsequence)

Trilogy to solve the problem of playing chess first and then

DDD landing practice repeat record of theoretical training & Event storm

2022.05.29 (lc_6079_price reduction)
![[advanced C language] data storage [part I] [ten thousand words summary]](/img/d3/077189a235fd688d4504b7a62456e3.png)
[advanced C language] data storage [part I] [ten thousand words summary]
![[advanced C language] data storage [Part 2] [ten thousand words summary]](/img/b5/4e346cb971b0574faf0164d3dcd9c8.png)
[advanced C language] data storage [Part 2] [ten thousand words summary]

This article introduces you to j.u.c's futuretask, fork/join framework and BlockingQueue
Ding Dong grabs vegetables - monitoring and pushing tools for delivery period
随机推荐
最近的工作
腾讯Libco协程开源库 源码分析(三)---- 探索协程切换流程 汇编寄存器保存 高效保存协程环境
Rmarkdown easily input mathematical formula
When the college entrance examination is opened, VR panorama can see the test site in this way
2022最强版应届生软件测试面试攻略,助你直通大厂
改变世界的开发者丨玩转“俄罗斯方块”的瑶光少年
DDD落地实践复盘 - 记理论培训&事件风暴
APICloud可视化开发新手图文教程
Summary of "performance test" of special test
高考后选择哪所学校?VR全景校园全方位展示
騰訊Libco協程開源庫 源碼分析(二)---- 柿子先從軟的捏 入手示例代碼 正式開始探究源碼
How do big factories write data analysis reports?
专项测试之「 性能测试」总结
Docker/Rancher2部署redis:5.0.9
【C语言进阶】数据的存储【上篇】【万字总结】
用一个性能提升了666倍的小案例说明在TiDB中正确使用索引的重要性
恭喜 | 医学院那洁课题组通过多组学分析揭示JUNB在体外分化人造血祖细胞过程中的功能
Soft deletion of data - when? How to realize it?
Before we learn about high-performance computing, let's take a look at its history
【C语言】这些经典题型大家都掌握了吗?一文学会这些题