前言

虹软人脸识别组件,支持活体识别、离线识别、图片人脸特征识别、图片是否同一人对比、相机人脸识别或对比,虹软免费版请使https://ext.dcloud.net.cn/plugin?id=6084

功能

  • 支持活体识别、离线识别
  • 图片人脸特征识别(年龄、性别、3DAngle)
  • 两张图片是否是同一人对比
  • 相机活体识别出人脸,用于人脸注册保存到本地,便于后面身份鉴定时作对比
  • 相机活体人脸对比,用于鉴定身份,常用于支付前活体人脸身份鉴定

激活引擎

使用之前需要激活引擎,虹软官方注册账号,获取APP_ID、SDK_KEY,注意创建应用的时候iOS需要绑定包名(这里iOS的包名对应自定义基座时的Bundle ID(AppID)),Android需要绑定包名和签名(这里的包名对应自定义基座时Android包名,这里签名是打包证书对应的sha1值)
激活引擎可以放到App.vue的onLaunch里去,每次启动的时候激活就行了

var arcface = uni.requireNativePlugin("wrs-arcface");
var options = {};
options.appid = "xxxxx";
switch (uni.getSystemInfoSync().platform) {case 'android':options.sdkkey = 'xxx';break;case 'ios':options.sdkkey = 'xxx';break;default:break;
}
arcface.activeEngine(options, (resp) => {if (resp.result) {console.log("激活成功");} else {console.log("激活失败");}this.showMsg("引擎激活结果:" + JSON.stringify(resp))
});

获取图片人脸信息(年龄、性别、3DAngle)

var options = {url: “” // 本地图片地址或网络图片};
arcface.getImageFaceFeature(options, (resp) => {if (resp.result) {console.log("识别成功");} else {console.log("识别失败");}this.showMsg("图片识别结果:" + JSON.stringify(resp))
});

设置相机检测角度

arcface.setVideoAngle({videoAngle: "all" // 0:仅检测0度 90:仅检测90度  180:仅检测180度  270:仅检测270度 all:检测0、90、270、180全角度
});

判断2个人脸图是否是同一个人

var options = {url1: “”, // 图片1地址,本地图片地址或网络图片url2: ”“ // 图片2地址
};
arcface.getSimilarity(options, (resp) => {if (resp.result) {var similarity = resp.similarity;if (similarity >= 0.80) { // 一般相似度大于0.8基本上就是同一个人了console.log("是同一个人");} else {console.log("不是同一个人");}}this.showMsg("获取相似度结果:" + JSON.stringify(resp))
});

摄像机人脸识别或人脸身份对比鉴定

<wrs-arcfacevideo ref='arcfacevideo' :style="'width:'+width+'px;height:'+height+'px;'" :config="config" @resultCallback="resultCallback"></wrs-arcfacevideo>config: {mode: 'recognize' ,// 模式,支持recognize、compare,recognize表示从摄像头识别人脸,一般用于人脸注册保存到本地,compare表示从摄像头识别出某个人,一般用于身份鉴权bgColor: "#000000", // 背景颜色anchorFrame: {bgImage: frameImage, // 人脸框图片left: left, // 人脸框左边距,单位 dptop: top, // 人脸框上边距width: frameWidth,// 人脸框宽度height: frameHeight // 人脸框高度},startFace:{}}

config属性:

  • bgColor: 背景颜色
  • anchorFrame: 人脸框
  • anchorFrame.bgImage: 人脸框图片
  • anchorFrame.left: 人脸框左边距,单位 dp
  • anchorFrame.top:人脸框上边距
  • anchorFrame.width: 人脸框宽度
  • anchorFrame.height: 人脸框高度
  • startFace: 开始识别人脸,如果config里有startFace参数则自动开始人脸业务,否则需要手动调用startFace()方法
    config.startFace对象的参数如下:
  • mode: 模式,支持recognize、compare,recognize表示从摄像头识别人脸,一般用于人脸注册保存到本地,compare表示从摄像头识别出某个人,一般用于身份鉴权
  • compareImage 人脸对图片,用于mode为recognize识别对比模式时作相机对比图片
  • compareImage.type: 图片类型,支持url、base64,url表示图片地址,支持本地地址和网络地址,base64表示图片base64的字符串
  • compareImage.value:图片类型对应的值
  • similarity: 相似度,用于mode为recognize模式时相似度大于这个值时认为是同一个人
  • liveness: 是否需要活体识别
  • faceNeedInRect: 人脸是否需要在anchorFrame人脸框内
  • needBase64Image: 识别到的图片是否需要进行base64编码返回,base64编码在Android上比较慢
  • saveImageFilePath: 识别到的图片是否需要保存为文件,如果不需要saveImageFilePath值不用传或传空

方法:
停止摄像头

this.$refs.arcfacevideo.stop();

开始摄像头,组件默认已经开启摄像头

this.$refs.arcfacevideo.start();

事件
@resultCallback
mode模式为recognize时,识别到人时回调
mode模式为compare时,识别到人,且大于等于相似度时回调

开始识别人脸

var params = {};
this.$refs.arcfacevideo.startFace(params);

params参数见上面的config.startFace

切换相机前后摄像头

this.$refs.arcfacevideo.switchCamera()

完整demo

index.nvue

<template><div><text>虹软(免费版)人脸识别</text><button @click="activeEngine()">激活引擎</button><button @click="getImageFaceFeature()">获取图片人脸信息(年龄、性别、3DAngle)</button><button @click="getSimilarity()">判断2个人脸图是否是同一个人</button><button @click="video_page()">摄像头识别</button><text class="log">{{msg}}</text></div>
</template><script>String.prototype.endWith = function(endStr) {var d = this.length - endStr.length;return (d >= 0 && this.lastIndexOf(endStr) == d)}var arcface = uni.requireNativePlugin("wrs-arcface");export default {data() {return {msg: "",}},methods: {activeEngine: function() {var options = {};options.appid = "xxx";switch (uni.getSystemInfoSync().platform) {case 'android':options.sdkkey = 'xxx';break;case 'ios':options.sdkkey = 'xxx';break;default:break;}arcface.activeEngine(options, (resp) => {if (resp.result) {console.log("激活成功");} else {console.log("激活失败");}this.showMsg("引擎激活结果:" + JSON.stringify(resp))});},getImageFaceFeature: function() {var path = "_www";var absPath = plus.io.convertLocalFileSystemURL(path);console.log("absPath:" + absPath);// Android获取的absPath以/结尾,iOS获取的absPath不是/结尾if (absPath.endWith('/')) {absPath = absPath.substring(0, absPath.length - 1);}var imagePath = absPath + "/static/1.jpeg";console.log("imagePath:" + imagePath);var options = {url: imagePath};arcface.getImageFaceFeature(options, (resp) => {if (resp.result) {console.log("识别成功");} else {console.log("识别失败");}this.showMsg("图片识别结果:" + JSON.stringify(resp))});},getSimilarity: function() {var path = "_www";var absPath = plus.io.convertLocalFileSystemURL(path);// Android获取的absPath以/结尾,iOS获取的absPath不是/结尾if (absPath.endWith('/')) {absPath = absPath.substring(0, absPath.length - 1);}var url1 = absPath + "/static/yifei1.jpeg";var url2 = absPath + "/static/yifei2.jpeg"var options = {url1: url1,url2: url2};arcface.getSimilarity(options, (resp) => {if (resp.result) {var similarity = resp.similarity;if (similarity >= 0.80) { // 一般相似度大于0.8基本上就是同一个人了console.log("是同一个人");} else {console.log("不是同一个人");}}this.showMsg("获取相似度结果:" + JSON.stringify(resp))});},video_page: function() {uni.navigateTo({url: './video_face'});},showMsg: function(msg) {console.log(msg);this.msg = msg;}}}
</script><style>.btn {margin-top: 25rpt;}
</style>

video_face.nvue

<template><div><wrs-arcfacevideo ref='arcfacevideo' :style="'width:'+width+'px;height:'+height+'px;'" :config="config"@resultCallback="resultCallback"></wrs-arcfacevideo></div>
</template><script>String.prototype.endWith = function(endStr) {var d = this.length - endStr.length;return (d >= 0 && this.lastIndexOf(endStr) == d)}export default {data() {const {windowWidth,windowHeight,statusBarHeight} = uni.getSystemInfoSync();var path = "_www";var absPath = plus.io.convertLocalFileSystemURL(path);// Android获取的absPath以/结尾,iOS获取的absPath不是/结尾if (absPath.endWith('/')) {absPath = absPath.substring(0, absPath.length - 1);}var imagePath = absPath + "/static/person.png"var frameImage = absPath + "/static/facesign_border.png";// 人脸框宽度var frameWidth = windowWidth * 0.8;// 图片比例var imageRatio = 298 / 343;// 人脸框高度var frameHeight = frameWidth / imageRatio;var left = (windowWidth - frameWidth) / 2.0;var top = 100;var bottom = windowHeight - frameHeight - top;return {height: windowHeight,width: windowWidth,config: {bgColor: "#000000", // 背景颜色anchorFrame: { // 人脸框bgImage: frameImage, // 人脸框图片left: left, // 人脸框左边距,单位 dptop: top, // 人脸框上边距width: frameWidth, // 人脸框宽度height: frameHeight // 人脸框高度},startFace:{} // 如果config里有startFace参数则自动开始人脸业务,否则需要手动调用startFace()方法},msg: ""}},onReady(){this.startFace(); // 注意调用startFace()方法的时机,相机},onLoad:function() {console.log("onLoad");console.log("onLoad this:" + this);var _self = this;setTimeout(function(){console.log("setTimeout");console.log("setTimeout this:" + this);},1000);},onShow() {console.log("onShow");console.log("onShow this:" + this);},onUnload() {this.$refs.arcfacevideo.stop();},methods: {startFace: function(){console.log("startFace000");var mode = "recognize";var base64 = "";try {base64 = uni.getStorageSync('faceData_key');if (base64 && base64.length > 0) {mode = "compare";} else {mode = "recognize";}} catch (e) {// errorconsole.log("getStorageSync error:" + e.message);}var saveImageFilePath = "";switch (uni.getSystemInfoSync().platform) {case 'android':saveImageFilePath = "/sdcard/Download/face.png";break;case 'ios':var absPath = plus.io.convertLocalFileSystemURL('_documents');// Android获取的absPath以/结尾,iOS获取的absPath不是/结尾if (absPath.endWith('/')) {absPath = absPath.substring(0, absPath.length - 1);};saveImageFilePath = absPath + "/face.png";break;default:break;}    var params = {mode: mode, // 模式,支持recognize、compare,recognize表示从摄像头识别人脸,一般用于人脸注册保存到本地,compare表示从摄像头识别出某个人,一般用于身份鉴权compareImage: {type: 'url', //  类型,支持url、base64,url表示图片地址,支持本地地址和网络地址,base64表示图片base64的字符串value: saveImageFilePath}, // 比较图片地址similarity: 0.8, // 相似度liveness: true, // 是否活体识别faceNeedInRect: false, // 人脸是否需要在anchorFrame人脸框内needBase64Image: false, // 识别到的图片是否需要进行base64编码返回,base64编码在Android上比较慢saveImageFilePath: saveImageFilePath // 识别到的图片是否需要保存为文件,如果不需要saveImageFilePath值不用传或传空};this.$refs.arcfacevideo.startFace(params);},resultCallback: function(resp) {var str = JSON.stringify(resp);console.log("resultCallback:" + str);if (null != resp.detail) {if(this.model == "compare") {console.log("识别成功");} else {var imageBase64 = resp.detail.imageBase64;try {uni.setStorageSync('faceData_key', imageBase64);} catch (e) {console.log("setStorageSync 保存失败:" + e.message);}}this.$refs.arcfacevideo.stop();uni.navigateBack({delta: 1});} else {console.log("识别失败");}}}}
</script><style></style>

联系方式:QQ(252797991)

如果觉得可以就点个

wrs-arcface虹软人脸识别相关推荐

  1. 虹软java接摄像头_虹软人脸识别SDK(java+linux/window) 初试

    虹软人脸识别全平台demo调用-快速上手之服务端Windows篇 demo名称:ArcFace 2.2 Windows(86) Demo [C++] 一 环境配置: 1) 安装VS2013环境安装包( ...

  2. 虹软人脸识别 - 人脸特征数据的存取

    虹软人脸识别 - 人脸特征数据的存取 文章目录 虹软人脸识别 - 人脸特征数据的存取 一.简介 二.数据库应用 1. 连接数据库 2. 建表 3. 注册人脸并保存其特征值到数据库 4. 获取人脸特征数 ...

  3. unity接入实现人脸识别应用-基于虹软人脸识别算法4.0

    一.准备工作 1.下载虹软人脸识别增值版SDK 4.0 1)注册并登录开发者中心 2)下载虹软人脸识别SDK 2.安装Unity3D及Visual Studio 2019开发环境 1)安装Unity ...

  4. C# 实现人脸识别一 (运用虹软人脸识别引擎)

    知识背景: 下载虹软人脸识别引擎 下载地址: http://www.arcsoft.com.cn/ai/arcface.html 目前虹软人脸识别引擎有3个平台,其中Windows与iOS是基于C++ ...

  5. 人脸识别 android p,虹软人脸识别 - faceId及IR活体检测的更新介绍

    虹软人脸识别 - faceId及IR活体检测的介绍 前几天虹软推出了 Android ArcFace 2.2版本的SDK,相比于2.1版本,2.2版本中的变化如下: VIDEO模式新增faceId(类 ...

  6. 虹软人脸识别3.0 - 图像数据结构介绍(Android)

    从虹软开放了2.0版本SDK以来,由于具有免费.离线使用的特点,我们公司在人脸识别门禁应用中使用了虹软SDK,识别效果还不错,因此比较关注虹软SDK的官方动态.近期上线了ArcFace 3.0 SDK ...

  7. 虹软android工程师,虹软人脸识别技术公开课开讲!AI工程师如何快速进阶

    原标题:虹软人脸识别技术公开课开讲!AI工程师如何快速进阶 随着刷脸乘坐公交.公租房人脸识别管理系统.景区人证核验入园等创新应用的加速普及,人脸识别技术已经在广泛的行业.领域中得到使用.在见证人脸识别 ...

  8. 虹软人脸识别3.0 - 图像数据结构介绍(C++)

    从虹软开放了2.0版本SDK以来,由于具有免费.离线使用的特点,我们公司在人脸识别门禁应用中使用了虹软SDK,识别效果还不错,因此比较关注虹软SDK的官方动态.近期上线了ArcFace 3.0 SDK ...

  9. 虹软人脸识别WPF版本,含活体检测

    虹软人脸识别WPF版本,3.0类库,含活体检测 源码地址: https://gitee.com/dacaba/arcface-demo-csharp-wpf3 将对应appid和appkey替换App ...

最新文章

  1. From 《visual C++ 6.0开发工具与调试》
  2. php中的替换函数,php字符串中替换函数是什么
  3. 开源路由器爱好者迎来利好 Linksys不变
  4. 设计一个函数能够取出字符串中指定的字符
  5. 《Windows PowerShell实战指南(第2版)》——1.4 搭建自己的实验环境
  6. ROS-创建功能包和节点
  7. js如何提高for循环的效率_如何提高rv减速机的散热效率
  8. Oracle完全手册,Oracle_11g+Oracle Sqldeveloper 安装完全手册(for win 7 64x)
  9. Ubuntu时间管理方法
  10. 非双一流普通院校毕业,你凭什么斩获 BAT 的 Offer?
  11. linux 静态连接失败,Windows7下archlinux静态网络配置错误连不上网怎么办?
  12. java 打印excel
  13. 重构——62提炼子类(Extract Subclass)
  14. 【礼仪大赛策划方案手段】 问穿正装的礼节是什么?到底何为正装?休闲正装?
  15. Keil MDK5安装详细步骤
  16. Ubuntu创建用户
  17. TLC5615 产生频率可变的正弦波
  18. 今天的一点杂感-20220414
  19. 操作系统知识点总结和题集大杂烩
  20. 联想新服务器怎么装系统教程,联想小新重装win7系统的详细教程图解

热门文章

  1. 前端优化系列之一:dns预获取 dns-prefetch 提升页面载入速度
  2. BZOJ2275[Coci2010]HRPA——斐波那契博弈
  3. 接口测试(postman jmeter)
  4. div 下 的img水平居中
  5. [转]Ext Grid控件的配置与方法
  6. IOS中打开应用实现检查更新的功能
  7. sql server 2008数据导入Oracle方法
  8. 鸡肋的PHP单例模式
  9. C#调用存储过程简单完整例子
  10. 显示DataGrid序号的一个适用的方法