/** * 点位追踪计数器 * * @alphaair * 20230516 created. **/ const utils = require("../../utils/utils"); const AiSport = requirePlugin("aiSport"); const SportBase = AiSport.sports.SportBase; /** * 点位追踪运动分析器 */ class SportPointTrack extends SportBase { _calc = null _prev = null _trend = null points = [] /** * 初始化分析器 * * @param {int?} pointThreshold 计算器取点评分阈值 */ constructor(pointThreshold) { super(pointThreshold); this.tickMode = true; this._calc = new AiSport.calc.CalcBase(); } pushing(body) { if (utils.isNone(body)) return; const lhip = body.keypoints.find(x => x.name == 'left_hip'); const rhip = body.keypoints.find(x => x.name == 'right_hip'); if (!lhip || !rhip) return; let y = lhip.y - rhip.y; y = Math.abs(y) / 2; y += Math.min(lhip.y, rhip.y); //首个点位 if (this._prev === null) { this._prev = y; this.points.push(y); return; } //平 if (y === this._prev) return; const t = y > this._prev; //首次趋势 if (this._trend === null) { this._trend = t; this._prev = y; return; } //趋势变化 if (t != this._trend) { this.emitTick(); this.points.push(this._prev); } this._trend = t; this._prev = y; } } SportPointTrack.KEY = "Point-Track"; SportPointTrack.NAME = "自定义-点位追踪"; module.exports = SportPointTrack;