收藏
回答

wx.faceDetect的使用,没有反应?

initData:function() {

      var that=this;

      //that.setData({tipsText:'测试'});

      console.log(that.data.tipsText);

      // #ifdef MP-WEIXIN

      wx.initFaceDetect();

      const context = wx.createCameraContext();

      const listener = context.onCameraFrame((frame) => {

        console.log(frame.data instanceof ArrayBuffer, frame.width, frame.height)

        wx.faceDetect({

          frameBuffer: frame.data,

          width: frame.width,

          height: frame.height,

          enablePoint: true,

          enableConf: true,

          enableAngle: true,

          enableMultiFace: true,

          success:function (faceData){

            console.log(faceData)

            let face = faceData.faceInfo[0]

            if(faceData.x == -1 || faceData.y == -1{

              that.data.tipsText = '检测不到人脸'

            }

            if(faceData.faceInfo.length > 1{

              that.data.tipsText = '请保证只有一人做认证'

            } else {

              if(face.angleArray.pitch >= 0.1 || face.angleArray.roll >= 0.1 || face.angleArray.yaw >= 0.1{

                that.data.tipsText = '请平视摄像头'

              } else if(face.confArray.global <= 0.8 || face.confArray.leftEye <= 0.8 || face.confArray.mouth <= 0.8 || face.confArray.nose <= 0.8 || face.confArray.rightEye <= 0.8{

                that.tipsText = '请勿遮挡五官'

              } else {

                that.data.tipsText = '人脸认证成功'


                // 这里可以写自己的逻辑了

              }

            }

          },

          fail:function  (err)  {

            console.log(err)

            if(err.x == -1 || err.y == -1{

              that.data.tipsText = '检测不到人脸'

            } else {

              that.data.tipsText = '网络错误,请退出页面重试'

            }

          },

          complete: function () {

            that.data.tipsText = '完成一次测试';

          }

        })

      })

      listener.start()

      // #endif

    }

没有任何反应

回答关注问题邀请回答
收藏

1 个回答

登录 后发表内容