欢迎来到258分享网,纯净的网络源码分享基地!

258资源分享网

全部作品
全部作品
网站源码
微信源码
素材特效
源码插件
视频教程
建站学院
热门搜索: 织梦  农业种植  农业  安全设置  官方
258资源分享 > 建站学院 > 微信开发 > 小程序--人脸识别功能(百度ai)

推荐下载

HTML5响应式自适应网咯设计

2020-05-12   浏览:736

高端HTML5响应式企业通用网

2020-05-06   浏览:517

html5响应式外贸网站英文版

2020-05-08   浏览:505

HTML5自适应律师工作室类网

2020-04-04   浏览:501

HTML5影视传媒文化公司类网

2020-05-12   浏览:495

小程序--人脸识别功能(百度ai)

发布时间:2020-10-01  
接入流程 1. 按照文档获取AppID、API Key、Secret Key,进行Access Token(用户身份验证和授权的凭证)的生成 const getBaiduToken = function () { return new Promise((resolve, reject) => { //自行获取APIKey、SecretKey const apiKey = APIKey; const secKey = SecretKey; const tokenUrl = `https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=${apiKey}&client_secret=${secKey}`; wx.request({ url: tokenUrl, method: 'POST', dataType: "json", header: { 'content-type': 'application/json; charset=UTF-8' }, success: function (res) { resolve(res); }, fail: function (res) { wx.hideLoading(); wx.showToast({ title: '网络错误,请重试!', icon: 'none', duration: 2000 }) reject(res); }, complete: function (res) { resolve(res); } }) }) }  
2. 选择人脸识别-->人脸检测,人脸识别接口分为V2和V3两个版本,确认在百度云后台获得的是V2还是v3版本接口权限。 //封装识别方法 const getImgIdentify = function(tokenUrl, data){ return new Promise((resolve, reject) => { const detectUrl = `https://aip.baidubce.com/rest/2.0/face/v3/detect?access_token=${tokenUrl}`; wx.request({ url: detectUrl, data: data, method: 'POST', dataType: "json", header: { 'content-type': 'Content-Type:application/json; charset=UTF-8' }, success: function (res) { resolve(res); }, fail: function (res) { wx.hideLoading(); wx.showToast({ title: '网络错误,请重试!', icon: 'none', duration: 2000 }) reject(res); }, complete: function (res) { resolve(res); } }) }) }  
3. 调用识别方法 getBaiduToken().then((res) => { let token = res.data.access_token; let data = { "image": self.data.img, "image_type":"URL", "face_field":"ge,beauty,expression,face_shape,gender,glasses,landmark,race,quality,eye_status,emotion,face_type" } util.getImgIdentify(token, data).then((res)=>{ //百度接口返回的结果 let score = parseInt(res.data.result.face_list[0].beauty); self.setData({ score: score, }) }) })  
4. 结果如下:

小程序--人脸识别功能(百度ai)

哼~一点都不准

本文标签

:备案管家服务帮您把复杂流程变简单,解决您在进行网站备案过程中遇到的效率低下和成功率不高的问题。个人300/2个域名,企业500/5个域名,qq1650004.