相思资源网 Design By www.200059.com

本文介绍了小程序实现人脸识别功能,分享给大家,具体如下:

文档中心: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"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"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)

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

标签:
小程序,人脸识别

相思资源网 Design By www.200059.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
相思资源网 Design By www.200059.com

评论“小程序实现人脸识别功能(百度ai)”

暂无小程序实现人脸识别功能(百度ai)的评论...

RTX 5090要首发 性能要翻倍!三星展示GDDR7显存

三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。

首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。

据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。