120 lines
3.2 KiB
JavaScript
120 lines
3.2 KiB
JavaScript
![]() |
const AiSport = requirePlugin("aiSport");
|
|||
|
const humanDetection = AiSport.humanDetection;
|
|||
|
const BodyDebugClient = AiSport.BodyDebugClient;
|
|||
|
|
|||
|
Page({
|
|||
|
data: {
|
|||
|
isDetecting: false,
|
|||
|
ve: null,
|
|||
|
enhanced: false,
|
|||
|
frameWidth: 480,
|
|||
|
frameHeight: 640,
|
|||
|
score: 0,
|
|||
|
isDetected: false,
|
|||
|
isDevelopmentMode: false,
|
|||
|
isPushback: false
|
|||
|
},
|
|||
|
|
|||
|
onLoad() {
|
|||
|
// 初始化配置
|
|||
|
this.setData({
|
|||
|
ve: humanDetection.getVe(),
|
|||
|
enhanced: humanDetection.isEnhanced()
|
|||
|
});
|
|||
|
|
|||
|
// 环境判断(微信小程序环境判断方式)
|
|||
|
const accountInfo = wx.getAccountInfoSync();
|
|||
|
this.setData({
|
|||
|
isDevelopmentMode: accountInfo.miniProgram.envVersion === 'develop'
|
|||
|
});
|
|||
|
},
|
|||
|
|
|||
|
onReady() {
|
|||
|
// 获取组件引用
|
|||
|
this.humanComp = this.selectComponent('#humanDetection');
|
|||
|
},
|
|||
|
|
|||
|
async initPushbackChannel() {
|
|||
|
if (this.debugClient)
|
|||
|
return true;
|
|||
|
|
|||
|
//请务必关必调试工具电脑的防火墙,保持手机与手机的畅通,替换您电话的URL,关闭域名校验、真机打开vconsole
|
|||
|
let client = new BodyDebugClient('http://192.168.5.10:20231');
|
|||
|
client.queueSize = 12;
|
|||
|
|
|||
|
let testOk = await client.testAsync();
|
|||
|
if (!testOk) {
|
|||
|
wx.showToast({
|
|||
|
title: '与工具通信异常,请检查网络。',
|
|||
|
icon: 'none'
|
|||
|
});
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
console.info('与调试工具通信正常。');
|
|||
|
await client.connectAsync();
|
|||
|
this.debugClient = client;
|
|||
|
return true;
|
|||
|
},
|
|||
|
|
|||
|
doPushback() {
|
|||
|
//请勿在识别帧的同时同步调用本回传接口,以免丢帧或UI卡死
|
|||
|
if (!this.debugClient)
|
|||
|
return;
|
|||
|
|
|||
|
wx.showLoading({ title: '回传帧数据...' });
|
|||
|
this.debugClient.syncing((idx, total) => {
|
|||
|
wx.hideLoading();
|
|||
|
if (idx >= total)
|
|||
|
return;
|
|||
|
|
|||
|
wx.showLoading({
|
|||
|
title: `同步进度${idx}/${total}`
|
|||
|
});
|
|||
|
});
|
|||
|
},
|
|||
|
|
|||
|
onStartStop() {
|
|||
|
if (!this.data.isDetecting) {
|
|||
|
this.humanComp.startCapture();
|
|||
|
this.setData({ isDetecting: true });
|
|||
|
} else {
|
|||
|
this.humanComp.stopCapture();
|
|||
|
this.setData({ isDetecting: false });
|
|||
|
this.doPushback();
|
|||
|
}
|
|||
|
},
|
|||
|
|
|||
|
onHumanDetecting(e) {
|
|||
|
const { human, frame } = e.detail;
|
|||
|
|
|||
|
if (!human) {
|
|||
|
this.setData({
|
|||
|
score: 0,
|
|||
|
isDetected: false
|
|||
|
});
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
this.setData({
|
|||
|
isDetected: true,
|
|||
|
frameWidth: human.width,
|
|||
|
frameHeight: human.height,
|
|||
|
score: human.score
|
|||
|
});
|
|||
|
//入队暂存
|
|||
|
if (this.data.isPushback) {
|
|||
|
this.debugClient.enqueue(frame, human);
|
|||
|
}
|
|||
|
},
|
|||
|
|
|||
|
async onPushback() {
|
|||
|
if (this.data.isPushback) {
|
|||
|
this.setData({ isPushback: false });
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
const isConnect = await this.initPushbackChannel();
|
|||
|
this.setData({ isPushback: isConnect });
|
|||
|
}
|
|||
|
})
|