国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 課堂 > 小程序 > 正文

小程序實現人臉識別功能(百度ai)

2020-03-21 16:04:32
字體:
來源:轉載
供稿:網友

本文介紹了小程序實現人臉識別功能,分享給大家,具體如下:

文檔中心: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. 結果如下:

小程序,人臉識別,百度ai,小程序開發

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 古田县| 徐水县| 满城县| 安图县| 三门峡市| 潞西市| 喀喇沁旗| 盐津县| 南陵县| 乌苏市| 仁布县| 元氏县| 新昌县| 云霄县| 安仁县| 固始县| 泰安市| 大庆市| 和龙市| 德惠市| 柞水县| 吐鲁番市| 富阳市| 大方县| 广东省| 辽宁省| 嘉兴市| 黄石市| 邹平县| 茶陵县| 宁德市| 德令哈市| 哈密市| 岢岚县| 江阴市| 鄂州市| 五大连池市| 蚌埠市| 云南省| 陆丰市| 格尔木市|