最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

小程序?qū)崿F(xiàn)人臉識別功能(百度ai)

 更新時間:2018年12月23日 10:49:56   作者:T_one  
這篇文章主要介紹了小程序?qū)崿F(xiàn)人臉識別功能(百度ai),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

本文介紹了小程序?qū)崿F(xiàn)人臉識別功能,分享給大家,具體如下:

文檔中心:https://ai.baidu.com/docs#/Begin/a2bbf4b2

接入流程

1. 按照文檔獲取AppID、API Key、Secret Key,進(jìn)行Access Token(用戶身份驗(yàn)證和授權(quán)的憑證)的生成

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: '網(wǎng)絡(luò)錯誤,請重試!',
     icon: 'none',
     duration: 2000
    })
    reject(res);
   },
   complete: function (res) {
    resolve(res);
   }
  })
 })
}

2. 選擇人臉識別-->人臉檢測,人臉識別接口分為V2和V3兩個版本,確認(rèn)在百度云后臺獲得的是V2還是v3版本接口權(quán)限。

//封裝識別方法
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: '網(wǎng)絡(luò)錯誤,請重試!',
     icon: 'none',
     duration: 2000
    })
    reject(res);
   },
   complete: function (res) {
    resolve(res);
   }
  })
 })
}

3. 調(diào)用識別方法

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)=>{
  //百度接口返回的結(jié)果
  let score = parseInt(res.data.result.face_list[0].beauty);
  self.setData({
   score: score,
  })
 })
})

4. 結(jié)果如下:

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

永登县| 苍南县| 谷城县| 江安县| 洪湖市| 郓城县| 屏山县| 河池市| 东乡族自治县| 错那县| 确山县| 东方市| 顺平县| 黑河市| 博客| 牡丹江市| 布拖县| 霞浦县| 绥滨县| 阜平县| 邮箱| 黄龙县| 肇庆市| 金门县| 固原市| 于田县| 鹤峰县| 新宾| 合川市| 辽阳市| 开平市| 峨边| 阜康市| 临安市| 岚皋县| 墨江| 渭源县| 泊头市| 无锡市| 镇平县| 丽江市|