this.session.on('addAnchors', anchors => {
const anchor = anchors[0]
const {
width,
height
} = this.data
console.log('addAnchors')
if (anchor) {
this.setData({
frameShow: true,
frameX: anchor.origin.x * width,
frameY: anchor.origin.y * height,
frameWidth: anchor.size.width * width,
frameHeight: anchor.size.height * height,
})
}
})
this.session.on('updateAnchors', anchors => {
const anchor = anchors[0]
const {
width,
height
} = this.data
if (anchor) {
this.setData({
frameX: anchor.origin.x * width,
frameY: anchor.origin.y * height,
frameWidth: anchor.size.width * width,
frameHeight: anchor.size.height * height,
})
}
})
this.session.on('removeAnchors', anchors => {
this.setData({
frameShow: false,
})
})
基础库版本3.10.0,检测物体移出镜头后隔很久才监听到removeAnchors事件,参考的是官方的例子