手机版

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

时间:2021-08-28 来源:互联网 编辑:宝哥软件园 浏览:

本文介绍了小程序实现人脸识别功能,分享给大家,具体如下:

文档中心:https://ai。百度。com/docs #/Begin/a2 bbf4b 2

接入流程

1.按照文档获取应用程序标识、应用程序接口密钥、密钥,进行访问令牌(用户身份验证和授权的凭证)的生成

const getBaiduToken=function(){ 0返回新的承诺(解析,拒绝)={ //自行获取APIKey、SecretKey const APIKey=APIKey const secKey=SecretKey const令牌URL=`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' },成功:函数(RES){ resolve(RES);},fail:函数(RES){ wx。hide loading();wx.showToast({ title: '网络错误,请重试!',icon: "无“,工期: 2000 })拒绝(RES);},完成:功能(RES){ resolve(RES);} }) })}2.选择人脸识别-人脸检测,人脸识别接口分为V2和V3两个版本,确认在百度云后台获得的是V2还是v3版本接口权限。

//封装识别方法const GetIgnite=函数(标记Url,数据){返回新的承诺(解析,拒绝)={ 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' },成功:函数(RES){ resolve(RES);},fail:函数(RES){ wx。hide loading();wx.showToast({ title: '网络错误,请重试!',icon: "无“,工期: 2000 })拒绝(RES);},完成:功能(RES){ resolve(RES);} }) })}3.调用识别方法

getBaiduToken().然后((RES)={ let token=RES . data。access _ token让数据={ ' image ' : self。数据。img,' image_type':'URL ',' face_field':'ge,美颜,表情,脸型,性别,眼镜,地标,种族,质量,眼睛状态,情感,face _ type ' } util。getmgidentify(令牌,数据).然后((res)={ //百度接口返回的结果让score=parsent(RES . data。结果。face _ list[0]).美);self.setData({ score: score,}) })})4 .结果如下:

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。

版权声明:小程序实现人脸识别功能(百度ai)是由宝哥软件园云端程序自动收集整理而来。如果本文侵犯了你的权益,请联系本站底部QQ或者邮箱删除。