当前位置:网站首页>Uni develops wechat applet to customize automatic camera detection (portrait + ID card)
Uni develops wechat applet to customize automatic camera detection (portrait + ID card)
2022-06-22 15:50:00 【Shadow night with the wind】
Previously, I developed a wechat applet to take photos with a custom camera to detect portraits and ID cards . I have been looking forward to writing an article to record , Take advantage of the time , To sum up .
Demand point :
1、 Be able to shoot portraits on your own
2、 It can automatically take the front photo of the ID card
3、 Identify your ID card and compare it with your face ( This function depends on the business logic of the company , Not open for the time being )
Lead to :
1、 Use baidu ai Face detection function , So you need to register an application on Baidu open platform ( Select face detection )
2、 Camera function uni.createCameraContext() and takePhoto()
3、 Picture compression uni.compressImage
4、 Get system files uni.getFileSystemManager().readFile
In particular :
Baidu face detection obtains token
getAccessToken(){
console.log(323232)
let that = this;
// Each update 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;
// Get token And then began to test the portrait
setTimeout(()=>{
that.initBaiDuApiFunction()
},1000)
},fail(err) {
console.log(err)
}
})
},Detect face data
uni.request({
url: "https://aip.baidubce.com/rest/2.0/face/v3/detect?access_token=" + that.access_token,
data: {// Please view the specific parameters automatically 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) { // When a face is detected, start taking photos
let faceList = res.data.result.face_list[0];
let face_probability = faceList.face_probability > 0.6; // Face confidence
let quality = faceList.quality; // Face quality
let blur = quality.blur < 0.5; // Face blur 0-1 0 Clear 1 Fuzzy
// let illumination = quality.illumination > 100; // Facial illumination Not for the time being
// left_eye : 0.6, # The threshold of occlusion of the left eye
// right_eye : 0.6, # Right eye occlusion threshold
// nose : 0.7, # The threshold at which the nose is obscured
// mouth : 0.7, # The threshold of mouth occlusion
// left_cheek : 0.8, # The threshold of occlusion of the left cheek
// right_cheek : 0.8, # The threshold of occlusion of the right cheek
// chin_contour : 0.6, # Jaw occlusion threshold
let occlusion =quality.occlusion;// Occlusion
let location = faceList.location;// Avatar location information
let top = location.top;
let left = location.left;
let completeness = quality.completeness == 1; // Face integrity
if (face_probability && blur && completeness) {// Get a clear face and start identity detection
that.baseImage = 'data:image/png;base64,'+rr.data// Pictures obtained base64
uni.showToast({
title:" Get photos successfully "
})
that.$emit('changeDataReturn',{
baseImage:rr.data,// Needed base64 picture
allImage:that.baseImage ,// Full link base64 picture
})
}else{// Or start taking pictures again
setTimeout(()=>{
that.initBaiDuApiFunction()
},1000)
}
} else {// If no face is detected, start taking photos again
setTimeout(()=>{
that.initBaiDuApiFunction()
},1000)
}
},
fail:()=>{
// Call failed , Turn on manual reacquire
that.reloadByHand = true;
}
})design sketch :



The specific code is encapsulated as uni-app plug-in unit , The plug-in address is :
Arrange a wave of benefits :

边栏推荐
- 专业“搬砖”老司机总结的 12 条 SQL 优化方案,非常实用!
- Common operations in Visual Studio development
- 向量1(类和对象)
- nvarchar和varchar的区别
- Scala语言学习-04-函数作为参数传入函数-函数作为返回值
- Runmaide medical passed the hearing: Ping An capital was a shareholder with a loss of 630million during the year
- #进程地址空间
- mysql如何将字段修改为not null
- [Newman] postman generates beautiful test reports
- 还整成这样
猜你喜欢

Quickly play ci/cd graphical choreography

小白操作Win10扩充C盘(把D盘内存分给C盘)亲测多次有效

(pytorch advanced path 2) word embedding and position embedding

#进程地址空间

The IPO of Tian'an technology was terminated: Fosun and Jiuding were shareholders who planned to raise 350million yuan

基于最小化三维NDT距离的快速精确点云配准

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

英国考虑基于国家安全因素让Arm在伦敦上市

【单片机】【让蜂鸣器发声】认识蜂鸣器,让蜂鸣器发出你想要的声音

架构师之路,从「存储选型」起步
随机推荐
uni开发微信小程序自定义相机自动检测(人像+身份证)
专业“搬砖”老司机总结的 12 条 SQL 优化方案,非常实用!
Cross border integration, creativity and innovation to help improve the influence of cultural tourism night tour
[single chip microcomputer] [make buzzer sound] know the buzzer and let it make the sound you want
Jenkins 通过检查代码提交自动触发编译
洛谷P2466 [SDOI2008] Sue 的小球 题解
Recommend several AI Intelligent Platforms
DDD understanding of Domain Driven Design
“软件定义世界,开源共筑未来” 2022开放原子全球开源峰会7月底即将开启
Quickly play ci/cd graphical choreography
[Newman] postman generates beautiful test reports
FPGA collects DHT11 temperature and humidity
Quick sort_ sort
极致效率,云原生数据库TDSQL-C安身立命的根本
Common operations in Visual Studio development
2020年蓝桥杯省赛真题-走方格(DP/DFS)
【题目精刷】2023禾赛-FPGA
After 100 days, Xiaoyu built a robot communication community!! Now invite moderators!
向量1(类和对象)
米哈游六月社招火热开启!500+岗位,超多HC,就在这个夏天(附内推方式)
https://ext.dcloud.net.cn/plugin?id=8070