75 lines
1.8 KiB
JavaScript
75 lines
1.8 KiB
JavaScript
const AiSport = requirePlugin("aiSport");
|
|
const SportBase = AiSport.sports.SportBase;
|
|
const humanDetection = AiSport.humanDetection;
|
|
|
|
Page({
|
|
data: {
|
|
ve: null,
|
|
enhanced: false,
|
|
sportKey: null,
|
|
sportName: null,
|
|
isDetecting: false,
|
|
isDetected: false,
|
|
counts: 0,
|
|
times: 0
|
|
},
|
|
|
|
onLoad(options) {
|
|
const that = this;
|
|
|
|
this.setData({
|
|
sportKey: options.sportKey,
|
|
sportName:SportBase.SPORTS.find(x => x.key === options.sportKey).name
|
|
})
|
|
|
|
this.sport = SportBase.create(options.sportKey);
|
|
|
|
//调整跳绳检测参数
|
|
// if (options.sportKey == 'Rope-Skipping') {
|
|
// const rules = that.sport.rules;
|
|
// rules.shakeRate = 0.02;
|
|
// rules.base.rules[2].rules[0].angle = 80;
|
|
// rules.base.rules[2].rules[1].angle = 80;
|
|
// }
|
|
|
|
this.sport.onTick = (cnt, times) => {
|
|
that.setData({
|
|
counts: cnt,
|
|
times: that.sport.toTimesString()
|
|
});
|
|
};
|
|
|
|
this.setData({
|
|
ve: humanDetection.getVe(),
|
|
enhanced: humanDetection.isEnhanced()
|
|
});
|
|
},
|
|
onReady() {
|
|
// 获取组件引用
|
|
this.humanComp = this.selectComponent('#humanDetection');
|
|
},
|
|
onHumanDetecting(e) {
|
|
const human = e.detail.human;
|
|
this.sport.pushing(human);
|
|
},
|
|
|
|
onStartStop() {
|
|
|
|
if (this.data.isDetecting) {
|
|
this.humanComp.stopCapture();
|
|
this.setData({
|
|
isDetecting: false
|
|
});
|
|
return;
|
|
}
|
|
|
|
this.sport.reset();
|
|
this.sport.start();
|
|
this.humanComp.startCapture();
|
|
this.setData({
|
|
counts: 0,
|
|
times: 0,
|
|
isDetecting: true
|
|
});
|
|
}
|
|
}); |