最新国产好看的视频,伊人天堂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)文章

最新評論

九江县| 镇平县| 霍林郭勒市| 闽侯县| 临安市| 汉沽区| 新田县| 盘山县| 庆云县| 峨边| 宜黄县| 金平| 仙居县| 衡东县| 宝坻区| 哈巴河县| 巴东县| 科技| 三河市| 铁岭市| 澳门| 黎城县| 云南省| 贡嘎县| 焉耆| 丰原市| 卢龙县| 三河市| 治多县| 乌鲁木齐县| 连山| 巩留县| 从化市| 当阳市| 永丰县| 靖边县| 普兰县| 辰溪县| 潞城市| 元阳县| 贵港市|