静默式活体检测,是华为hms core机器学习服务所属的人脸活体检测能力,即无需用户配合做出张嘴、扭头、眨眼等动作,便可实时捕捉人脸,快速判断是否为活体,用户使用过程便捷,综合体验感较佳。
技术原理
静默活体检测能力使用rgb摄像头,通过屏幕拍摄出现的摩尔纹、纸质照片反光等一些细节信息进行甄别摄像头前的检测物是真实人脸,还是人脸翻拍图片、人脸翻拍屏幕、人脸面具等假脸攻击。同时,静默活体检测能力的活体数据覆盖光照、脸部饰品、性别、发型、面具材质等场景,对人脸存在的宏观环境进行分析,排除明显不可能存在人脸的场景。
静默活体检测能力的模型设计采用轻量化卷积模块,同时将模型的线性计算通过重参数化思想在推理阶段转成单个卷积或全连接模块。模型部署采用mindspore-lite推理框架,对算子进行裁剪,实现极致的包大小,更利于开发者集成应用。
应用场景
活体检测技术通常应用在人脸对比技术之前,比如在人脸识别手机解锁时,首先需要通过活体检测技术判别机器前出现的人脸是真脸还是假脸,然后再对比当前人脸与系统已录入人脸是否是同一人,这样可以防止当事人不在场的情况下,有人假冒当事人解锁手机,造成个人信息泄露等严重损失。
那么,如何才能集成静默活体检测能力呢?
集成步骤
1.开发准备
详细步骤可参考华为开发者联盟官网中的应用开发介绍:https://developer.huawei.com/consumer/cn/doc/development/hiai-guides/liveness-detection-0000001051386243?ha_source=hms1
静默活体检测提供两种调用方式,您可以根据需求选择相应的调用方式构建活体检测服务。
2.默认扫描界面
2.1 创建静默活体检测结果回调,用于获取检测结果。
private mllivenesscapture.callback callback = new mllivenesscapture.callback() {
@override
public void onsuccess(mllivenesscaptureresult result) {
// 检测成功的处理逻辑,检测结果可能是活体或者非活体。
}
@override
public void onfailure(int errorcode) {
// 检测未完成,如相机异常camera_error,添加失败的处理逻辑。
}
};
2.2 创建静默活体检测实例,启动检测。
mllivenesscapture capture = mllivenesscapture. getinstance();
capture.startdetect(activity, callback);
3.自定义扫描界面
3.1 创建mllivenessdetectview,并加载到activity布局。
- i.绑定相机预览界面,设置活体识别区域。
在相机预览流中,静默活体检测会对人脸在不在图像的中间进行判断,为了提高活体的通过率,建议人脸框放在屏幕中间,且活体识别区域比绘制的人脸框范围略大。
-
ii.设置是否检测口罩。
-
iii.设置结果回调。
-
iv.将mllivenessdetectview加载到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.对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();
}
更多关于机器学习服务介绍,请访问华为开发者联盟官网。 如果您在集成sdk或上架应用到华为应用市场时遇到问题,都可以在线提单。
了解更多详情>>
访问华为开发者联盟官网
获取开发指导文档
华为移动服务开源仓库地址:github、gitee
关注我们,第一时间了解 hms core 最新技术资讯~
发表评论