当前位置:网站首页>uni开发微信小程序自定义相机自动检测(人像+身份证)
uni开发微信小程序自定义相机自动检测(人像+身份证)
2022-06-22 14:32:00 【影夜随风】
之前开发过微信小程序自定义相机拍照检测人像和身份证检测。一直期望写篇文章记录一下,趁现在有点时间,总结一下。
需求点:
1、能够自定拍摄人像
2、能够自动拍摄身份证正面照
3、识别身份证并且和人脸照比对是否是本人(该功能因公司业务逻辑,暂不开放)
前置准备:
1、使用百度ai人脸检测功能,所以需要在百度开放平台注册一个应用(选择人脸检测)
2、相机功能 uni.createCameraContext()和 takePhoto()
3、图片压缩 uni.compressImage
4、获取系统文件uni.getFileSystemManager().readFile
特别说明:
百度人脸检测获取token
getAccessToken(){
console.log(323232)
let that = this;
// 每次更新access_token
let baiduApiData = that.baiduApiData;
uni.request({
url: "https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id="+baiduApiData.apikey+"&client_secret="+baiduApiData.SecretKey,
method: 'POST',
dataType: "json",
header: {
'content-type': 'application/json'
},
success: function(res) {
console.log(res,"-----")
that.access_token = res.data.access_token;
//获取到token后开始检测人像
setTimeout(()=>{
that.initBaiDuApiFunction()
},1000)
},fail(err) {
console.log(err)
}
})
},检测人脸数据
uni.request({
url: "https://aip.baidubce.com/rest/2.0/face/v3/detect?access_token=" + that.access_token,
data: {//具体参数请自动查看api
image: rr.data,
image_type: "BASE64",
max_face_num: 1,
face_field: 'quality',
},
method: 'POST',
dataType: "json",
header: {
'content-type': 'application/json'
},
success: function(res) {
console.log(5555)
console.log(res)
if (res.data.error_code === 0) { //检测到人脸就开启拍照
let faceList = res.data.result.face_list[0];
let face_probability = faceList.face_probability > 0.6; //人脸置信度
let quality = faceList.quality; //人脸质量
let blur = quality.blur < 0.5; //人脸模糊度 0-1 0清晰 1模糊
// let illumination = quality.illumination > 100; //脸部光照度 暂时不用
// left_eye : 0.6, #左眼被遮挡的阈值
// right_eye : 0.6, #右眼被遮挡的阈值
// nose : 0.7, #鼻子被遮挡的阈值
// mouth : 0.7, #嘴巴被遮挡的阈值
// left_cheek : 0.8, #左脸颊被遮挡的阈值
// right_cheek : 0.8, #右脸颊被遮挡的阈值
// chin_contour : 0.6, #下巴被遮挡阈值
let occlusion =quality.occlusion;//遮挡情况
let location = faceList.location;//头像位置信息
let top = location.top;
let left = location.left;
let completeness = quality.completeness == 1; //人脸完整度
if (face_probability && blur && completeness) {//获取人脸较为清晰可以开始身份检测
that.baseImage = 'data:image/png;base64,'+rr.data//获取到的图片base64
uni.showToast({
title:"获取照片成功"
})
that.$emit('changeDataReturn',{
baseImage:rr.data,//需要的base64图片
allImage:that.baseImage ,//完整链路的base64图片
})
}else{//否则重新开始拍照
setTimeout(()=>{
that.initBaiDuApiFunction()
},1000)
}
} else {//没有检测到人脸也重新开始拍照
setTimeout(()=>{
that.initBaiDuApiFunction()
},1000)
}
},
fail:()=>{
//调用失败,开启手动重新获取
that.reloadByHand = true;
}
})效果图:



具体代码封装为uni-app插件,插件地址为:
微信小程序自定义orc检测人像(ww-orc-idcard) - DCloud 插件市场自动检测人像或者证件照
https://ext.dcloud.net.cn/plugin?id=8070
安排一波福利:

边栏推荐
- Reconstruction practice of complex C-end project of acquisition technology
- "Forget to learn again" shell process control - 38. Introduction to while loop and until loop
- 【题目精刷】2023禾赛-FPGA
- 类似attention nlp
- 蓝桥杯2019年国赛最长子序列
- 数据资产管理:数据发现,发现什么,怎么发现?
- Ultimate efficiency is the foundation for the cloud native database tdsql-c to settle down
- Database connection pool: Code Directory
- mysql如何将字段修改为not null
- 向量2(友元及拷贝构造)
猜你喜欢

时隔17年,刘亦菲再次刷屏式爆红:普通人不想被淘汰,也要懂得这件事

I rely on the sideline to buy a house in full one year: the industry you despise will make a lot of money in the next ten years!

多年亿级流量下的高并发经验总结,都毫无保留地写在了这本书中

数据资产管理:数据发现,发现什么,怎么发现?

Those confusing user state & kernel state

Token processing during API encapsulation

Promoting compatibility and adaptation, enabling coordinated development of gbase may adaptation Express

社区文章|MOSN 构建 Subset 优化思路分享

New hybrid architecture iformer! Flexible migration of convolution and maximum pooling to transformer

Exploration and practice of dewu app data simulation platform
随机推荐
New hybrid architecture iformer! Flexible migration of convolution and maximum pooling to transformer
晒晒我这两年的私活单,业余时间月入6k,有份副业也太香啦
Tree structured binary tree
Promoting compatibility and adaptation, enabling coordinated development of gbase may adaptation Express
MongoDB在腾讯零售优码中的应用
Once, I had 5 part-time jobs just to buy a new earring for my girlfriend
"Forget to learn again" shell process control - 38. Introduction to while loop and until loop
关于 GIN 的路由树
『忘了再学』Shell流程控制 — 38、while循环和until循环介绍
那些没考上大学的人,后来过的怎样
向量1(类和对象)
Runmaide medical passed the hearing: Ping An capital was a shareholder with a loss of 630million during the year
做自媒体视频博主,必备的32个素材网站分享
Mitsubishi manipulator demo program
英国考虑基于国家安全因素让Arm在伦敦上市
Hello, big guys. Error reporting when using MySQL CDC for the first time
标准化、最值归一化、均值归一化应用场景的进阶思考
新版负载均衡WebClient CRUD
Database connection pool: implementation of connection pool function point
接了个私活项目,一下赚了15250,还有必要做主业吗?