更新记录
1.0.0(2026-04-30)
首版发布
平台兼容性
uni-app(4.76)
| Vue2 |
Vue2插件版本 |
Vue3 |
Vue3插件版本 |
Chrome |
Safari |
app-vue |
app-vue插件版本 |
app-nvue |
Android |
Android插件版本 |
iOS |
鸿蒙 |
| √ |
1.0.0 |
√ |
1.0.0 |
× |
× |
√ |
1.0.0 |
- |
5.0 |
1.0.0 |
× |
× |
| 微信小程序 |
支付宝小程序 |
抖音小程序 |
百度小程序 |
快手小程序 |
京东小程序 |
鸿蒙元服务 |
QQ小程序 |
飞书小程序 |
小红书小程序 |
快应用-华为 |
快应用-联盟 |
| × |
× |
× |
× |
× |
× |
× |
× |
× |
- |
× |
× |
uni-app x(4.76)
| Chrome |
Safari |
Android |
Android插件版本 |
iOS |
鸿蒙 |
微信小程序 |
| × |
× |
5.0 |
1.0.0 |
× |
× |
× |
其他
本插件为基于 google mlkit 的摄像头人脸注册与检测的 UTS Android 插件
使用场景有以下两种:
1.人脸注册
开发者通过本插件可以直接调用 Android 设备的摄像头,并嵌入到当前页面的指定位置,将自动检测人脸。如果识别到人脸,会调用回调函数一次,传递人脸照片临时文件的url,此时开发者应调用插件的stopCamera 方法关闭摄像头,并上传人脸照片到服务器进行人脸注册。如果注册成功则应调用插件的 deleteFile 方法来删除临时文件;如果注册失败,则应重新调用打开摄像头的方法,重新打开摄像头
2.人脸识别登录
开发者通过本插件可以直接调用 Android 设备的摄像头,并嵌入到当前页面的指定位置,将自动检测人脸。如果识别到人脸,会调用回调函数一次,传递人脸照片临时文件的url。此时开发者可上传人脸照片到服务器进行人脸比对和登录,比对失败或者网络异常的原因导致登录流程中断时,应调用本插件提供的 continueDetect 函数再次允许检测人脸成功后的持续回调。
可查看示例工程中的两个页面,其中:
1.index.vue 演示了人脸录入功能
import { startCamera as utsStartCamera, stopCamera, deleteFile,continueDetect } from '@/uni_modules/lhio-face-detect'
utsStartCamera({
x: left,
y: top+topInfo.fullHeaderHeight,
width: width,
height: height
}, (res) => {
if (res.code === -1) {
//打开摄像头失败
uni.showToast({
icon:'none',
title: res.message
})
}else if(res.code === 1 ){
console.log('onFaceDetected');
filePath.value = res.absolutePath ?? '';
uni.showToast({
icon:'none',
title: '检测到人脸咯'
})
plus.io.resolveLocalFileSystemURL(filePath.value, (entry) => {
console.log(entry.fullPath)
let reader = new plus.io.FileReader();
reader.onloadend = (e) => {
faceImgUrl.value = e.target.result; // base64 格式
stopCamera();
uni.showToast({
icon:'none',
title: '请点击提交按钮注册人脸!'
})
};
reader.readAsDataURL(entry);
}, (e) => {
uni.showToast({
icon:'none',
title: "读取文件失败: " + e.message
})
console.error("读取文件失败: " + e.message);
});
}else if(res.code === 2){
if(!isShowFaceDetectMsg.value){
isShowFaceDetectMsg.value = true;
uni.showToast({
icon:'none',
title: res.message
})
setTimeout(()=>{
isShowFaceDetectMsg.value = false;
},2000)
}
}
});
const submitFace = ()=>{
//通过 faceImgUrl.value 或者 filePath.value 提交照片到服务器进行人脸录入
uni.showToast({
icon:'none',
title: '通过 faceImgUrl.value 或者 filePath.value 提交照片到服务器进行人脸录入'
})
//上传完毕记得删除临时文件
if (filePath.value) {
deleteFile(filePath.value);
}
}
2.face_detect.vue 演示了人脸识别功能
import { startCamera as utsStartCamera, stopCamera, deleteFile,continueDetect } from '@/uni_modules/lhio-face-detect'
utsStartCamera({
x: left,
y: top+topInfo.fullHeaderHeight,
width: width,
height: height
}, (res) => {
if (res.code === -1) {
//打开摄像头失败
uni.showToast({
icon:'none',
title: res.message
})
}else if(res.code === 1 ){
console.log('onFaceDetected');
filePath.value = res.absolutePath ?? '';
uni.showToast({
icon:'none',
title: '检测到人脸咯'
})
plus.io.resolveLocalFileSystemURL(filePath.value, (entry) => {
console.log(entry.fullPath)
let reader = new plus.io.FileReader();
reader.onloadend = (e) => {
faceImgUrl.value = e.target.result; // base64 格式
stopCamera();
uni.showToast({
icon:'none',
title: '请点击提交按钮注册人脸!'
})
};
reader.readAsDataURL(entry);
}, (e) => {
uni.showToast({
icon:'none',
title: "读取文件失败: " + e.message
})
console.error("读取文件失败: " + e.message);
});
}else if(res.code === 2){
if(!isShowFaceDetectMsg.value){
isShowFaceDetectMsg.value = true;
uni.showToast({
icon:'none',
title: res.message
})
setTimeout(()=>{
isShowFaceDetectMsg.value = false;
},2000)
}
}
});