小程序实现人脸识别功能(百度ai)
2018-12-26 00:02
1241 查看
本文介绍了小程序实现人脸识别功能,分享给大家,具体如下:
文档中心:https://ai.baidu.com/docs#/Begin/a2bbf4b2
接入流程
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. 结果如下:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
您可能感兴趣的文章:
相关文章推荐
- 【Unity3d】在Unity3d中使用百度AI人脸识别功能
- PHP实现微信小程序人脸识别刷脸登录功能
- 用百度AI的OCR文字识别结合JAVA实现了图片的文字识别功能
- 用百度AI的OCR文字识别结合PHP实现了图片的文字识别功能
- PHP实现微信小程序人脸识别刷脸登录功能
- 调用百度AI实现人脸识别-Python
- 【基于百度AI的人脸识别Python实现】
- Java实现调用百度AI开放云平台(人脸识别API)
- python利用百度AI实现文字识别功能
- 【Unity3d】在Unity3d中使用百度AI人脸识别功能
- python 调用海康linux下demo的可执行程序,设置回调,实现人脸识别 以及实现抓拍功能
- 基于百度AI的人脸识别-Python
- 基于百度AI实现 车牌识别
- c# 利用AForge和百度AI开发实时人脸识别
- JAVA实现百度OCR文字识别功能
- 小程序web-view用wx.scanQRCode实现微信扫一扫功能,识别二维码——微信序web-view高级用法8
- PHP调用百度AI接口人脸识别-语音技术-文本识别-图像识别
- JAVA实现百度OCR文字识别功能
- 基于百度AI实现 车牌识别
- 调用OpenCV实现人脸识别功能