Appearance
使用方法
虹软人脸识别增值版5.0版支持在线激活,离线激活,支持图片人脸识别(可识别网络图片),活体检测,离线识别,相机预览旋转,相机人脸识别,批量注册(支持网络图片)等,识别率更高速度更快,支持保存用户的id和名称
注意
- 本插件为虹软人脸增值版5.0sdk,因为5.0底层模型修改所以不支持4.2版本直接升级
- 4.2版本插件地址:https://ext.dcloud.net.cn/plugin?id=15808
- 3.0免费版插件地址:https://ext.dcloud.net.cn/plugin?id=15096
联系作者

关注微信公众号可联系作者
官方文档
https://ai.arcsoft.com.cn/manual/docs#/190
SDK版本
ArcFace v5.0
插件地址
https://ext.dcloud.net.cn/plugin?id=21584
权限
- android.permission.CAMERA
- android.permission.WRITE_EXTERNAL_STORAGE
- android.permission.READ_EXTERNAL_STORAGE
- android.permission.READ_PHONE_STATE
API用法
仅提供了部分示例,完整示例请参考示例文件
用法
在需要使用插件的页面加载以下代码
js
import * as module from "@/uni_modules/leven-uts-arc-pro5"示例
vue
<template>
<view>
<uni-card title="激活">
<button type="primary" @click="requestPermission">申请权限</button>
<button type="primary" @click="getDeviceFinger">获取设备指纹信息</button>
<button type="primary" @click="activeOnline">在线激活</button>
<button type="primary" @click="activeOffline">离线激活</button>
<button type="primary" @click="isActivated">查询激活状态</button>
<button type="primary" @click="customFaceDataPath">自定义人脸数据存储路径</button>
</uni-card>
<uni-card class="uni-card-box" title="日志">
<view><text style="font-size: 14px; flex-wrap: wrap;">{{logStr}}</text></view>
</uni-card>
</view>
</template>
<script>
import * as module from "@/uni_modules/leven-uts-arc-pro5"
export default {
data() {
return {
logStr: "",
}
},
methods: {
// 申请权限
requestPermission() {
module.requestPermissions(res => {
this.writeLog("申请权限:" + JSON.stringify(res))
})
},
// 在线激活
activeOnline() {
module.activeOnline({
activeKey: "8551-11UP-712L-WWEY",
appId: "FPMZ54pFtPgHYQWoHgPWCJEfkh9X435ZbKCeJzbZc1N3",
sdkKey: "7yRrFX68rAFGPShnZ6t7FLXPdCoAxcmGJfhQ2w1owpFc"
}, res => {
this.writeLog("在线激活:" + JSON.stringify(res))
})
},
// 获取设备指纹信息
getDeviceFinger() {
module.getDeviceFinger(res => {
this.writeLog("获取设备指纹信息:" + JSON.stringify(res))
})
},
// 查询激活状态
isActivated() {
module.isActivated(res => {
this.writeLog("查询激活状态:" + JSON.stringify(res))
})
},
// 离线激活
activeOffline() {
module.activeOffline({
path: "/storage/emulated/0/Download/WeiXin/85Q111L6B11R1WNE.dat"
}, res => {
this.writeLog("离线激活:" + JSON.stringify(res))
})
},
// 自定义人脸数据存储路径
customFaceDataPath() {
module.customFaceDataPath({
//文件夹路径
path: "/storage/emulated/0/levenArcFacePro"
}, res => {
this.writeLog("自定义人脸数据存储路径:" + JSON.stringify(res))
})
},
showToast(content) {
console.log(content)
// uni.showToast({
// icon: "none",
// title: content
// })
},
// 写日志
writeLog(str) {
console.log(str);
let logStr = uni.$lv.date.format(null, "yyyy-mm-dd hh:MM:ss") + " " + str + "\n";
this.logStr = logStr + this.logStr;
}
}
}
</script>
<style>
</style>人脸识别组件使用
用法
在需要使用插件的页面添加以下代码
vue
<leven-uts-arc-face5 ref="refLevenArcFacePro" style="flex:1; height: 500px;" :config="config" @onError="onError"
@onCameraOpened="onCameraOpened" @onCameraClosed="onCameraClosed" @onCameraConfigurationChanged="onCameraConfigurationChanged"
@onInitResult="onInitResult" @onFaceResult="onFaceResult">
</leven-uts-arc-face5>示例
vue
<template>
<view>
<uni-card title="人脸识别">
<view style="flex:1; height: 500px; position: relative;">
<leven-uts-arc-face5 ref="refLevenArcFacePro" style="flex:1; height: 500px;" :config="config" @onError="onError"
@onCameraOpened="onCameraOpened" @onCameraClosed="onCameraClosed" @onCameraConfigurationChanged="onCameraConfigurationChanged"
@onInitResult="onInitResult" @onFaceResult="onFaceResult">
</leven-uts-arc-face5>
<!-- 组件内部自定义内容 -->
<cover-view v-if="imageBase64" style="position: absolute; right: 0; bottom: 0;">
<image :src="imageBase64" style="width: 170px; height: 170px;" mode="scaleToFill"></image>
</cover-view>
</view>
<view>
<button type="primary" @click="register">注册人脸</button>
<button type="primary" @click="switchCamera">切换相机</button>
<button type="primary" @click="stop">关闭预览</button>
<button type="primary" @click="start">开启预览</button>
<button type="primary" @click="closeFace">关闭人脸检测</button>
<button type="primary" @click="openFace">开启人脸检测</button>
<button type="primary" @click="getCameraData">摄像头数据</button>
</view>
</uni-card>
</view>
</template>
<script>
export default {
data() {
return {
//组件配置
config: {
//相机属性,所有的参数都可以不传,不传则按默认的
camera: {
// 相机预览旋转角度
rotation: 0,
//相机模式,1.前置,0.后置(默认)
facing: 1,
// 摄像机预览圆角,默认:0
radius: 50,
//预览分辨率,默认:[1280,720]
size: [1280, 720],
//是否锁定屏幕启动方向,默认:true
screenLocked: true
},
// 视频检测配置,所有参数都可以不传,不传则按默认的
video: {
// 视频检测角度,可接收参数,0,90,180,270,360(默认)
orient: 360,
// 人脸框是否处于X反向状态,如果未设置该参数人脸框和人脸处于反向请将该参数设置为true
isContraryX: false,
// 人脸框是否处于Y反向状态,如果未设置该参数人脸框和人脸处于反向请将该参数设置为true
isContraryY: false,
// 识别阈值(默认:0.8)
similar: 0.9,
// 是否进行活体检测(默认为true)
liveness: true,
//识别是否展示面部信息(默认为true)
showFaceInfo: false,
//活体检测阈值设置
livenessParams: {
//可见光活体检测阈值,默认:0.5
rgb: 0.5,
//红外活体检测阈值,默认:0.7
ir: 0.7
},
//是否显示人脸上方识别状态提示,默认:true
showFaceResultNotice: true,
//人脸识别尺寸,超过该尺寸才识别,否则不识别,可根据识别成功后返回的人脸尺寸进行调整,默认:0,不做人脸尺寸识别
faceSize: 300,
},
},
//注册的人脸图片
imageBase64: ""
}
},
methods: {
// 注册人脸
register() {
if (this.$refs.refLevenArcFacePro) {
this.$refs.refLevenArcFacePro.register({
// 注册后保存的id(可以不传该参数,默认时间戳)
id: "123",
//注册后保存的名字(可以不传该参数,默认时间戳)
name: "leven",
//同一人脸是否可以多次注册
registerMultiple: false,
}, res => {
if (res.code == 0) {
uni.$lv.func.toast("注册成功");
} else {
uni.$lv.func.toast(res.message);
}
});
}
},
// 切换相机
switchCamera() {
if (this.$refs.refLevenArcFacePro) {
this.$refs.refLevenArcFacePro.switchCamera(res => {
uni.$lv.func.toast(JSON.stringify(res));
});
}
},
// 摄像头数据
getCameraData() {
if (this.$refs.refLevenArcFacePro) {
this.$refs.refLevenArcFacePro.getCameraData(res => {
uni.$lv.func.toast(JSON.stringify(res));
});
}
},
// 关闭预览
stop() {
if (this.$refs.refLevenArcFacePro) {
this.$refs.refLevenArcFacePro.stop(res => {
uni.$lv.func.toast(JSON.stringify(res));
});
}
},
// 开启预览
start() {
if (this.$refs.refLevenArcFacePro) {
this.$refs.refLevenArcFacePro.start(res => {
uni.$lv.func.toast(JSON.stringify(res));
});
}
},
// 关闭人脸检测
closeFace() {
if (this.$refs.refLevenArcFacePro) {
this.$refs.refLevenArcFacePro.closeFace(res => {
uni.$lv.func.toast(JSON.stringify(res));
});
}
},
// 开启人脸检测
openFace() {
if (this.$refs.refLevenArcFacePro) {
this.$refs.refLevenArcFacePro.openFace(res => {
uni.$lv.func.toast(JSON.stringify(res));
});
}
},
// 错误事件
onError(e) {
let detail = e.detail || {};
uni.$lv.func.toast("错误事件:" + JSON.stringify(detail));
},
// 相机打开事件
onCameraOpened(e) {
console.log(e)
},
// 相机关闭事件
onCameraClosed(e) {
console.log(e)
},
// 相机配置改变事件
onCameraConfigurationChanged(e) {
console.log(e)
},
// 初始化结果事件
onInitResult(e) {
console.log(e)
},
// 人脸识别结果
onFaceResult(e) {
console.log(e)
let detail = e.detail;
if (detail.compareImageBase64) {
this.imageBase64 = "data:image/jpeg;base64," + detail.compareImageBase64
}
}
}
}
</script>
<style>
</style>