wx.stopFaceDetect 及 wx.faceDetect及wx.initFaceDetect()接口已确认停止维护,替代方案为 wx.createVKSession
onCameraFrame() {
// 初始化createVKSession
this.session = wx.createVKSession({
track: {
face: {
mode: 2
} // mode: 1 - 手动传入图像;2 - 使用摄像头
},
})
// 摄像头实时检测模式下,监测到人脸时,updateAnchors 事件会连续触发 (每帧触发一次)
this.session.on('updateAnchors', this.handleUpdateAnchors)
// 当人脸从相机中离开时,会触发 removeAnchors 事件
this.session.on('removeAnchors', this.handleremoveAnchors)
// 需要调用一次 start 以启动
this.session.start(errno => {
if (errno) {
// 如果失败,将返回 errno
} else {
// 否则,返回null,表示成功
this.listener.start()
}
})
},
handleUpdateAnchors(anchors) {
//监测到人脸时,自己的逻辑
},
handleremoveAnchors() {
//监测到人脸移出时的逻辑
},
取消监听
this.session.off('updateAnchors', this.handleUpdateAnchors);