本文介紹了小程序?qū)崿F(xiàn)人臉識別功能,分享給大家,具體如下:
公司主營業(yè)務:成都網(wǎng)站建設、成都網(wǎng)站設計、移動網(wǎng)站開發(fā)等業(yè)務。幫助企業(yè)客戶真正實現(xiàn)互聯(lián)網(wǎng)宣傳,提高企業(yè)的競爭能力。創(chuàng)新互聯(lián)建站是一支青春激揚、勤奮敬業(yè)、活力青春激揚、勤奮敬業(yè)、活力澎湃、和諧高效的團隊。公司秉承以“開放、自由、嚴謹、自律”為核心的企業(yè)文化,感謝他們對我們的高要求,感謝他們從不同領域給我們帶來的挑戰(zhàn),讓我們激情的團隊有機會用頭腦與智慧不斷的給客戶帶來驚喜。創(chuàng)新互聯(lián)建站推出化德免費做網(wǎng)站回饋大家。
文檔中心:https://ai.baidu.com/docs#/Begin/a2bbf4b2
接入流程
1. 按照文檔獲取AppID、API Key、Secret Key,進行Access Token(用戶身份驗證和授權(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)絡錯誤,請重試!', icon: 'none', duration: 2000 }) reject(res); }, complete: function (res) { resolve(res); } }) }) }
2. 選擇人臉識別-->人臉檢測,人臉識別接口分為V2和V3兩個版本,確認在百度云后臺獲得的是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)絡錯誤,請重試!', 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)容,希望對大家的學習有所幫助,也希望大家多多支持創(chuàng)新互聯(lián)。
分享文章:小程序?qū)崿F(xiàn)人臉識別功能(百度ai)
文章起源:http://chinadenli.net/article22/giehcc.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供小程序開發(fā)、網(wǎng)站內(nèi)鏈、網(wǎng)站營銷、云服務器、關(guān)鍵詞優(yōu)化、定制開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)