当前位置: 首页 > news >正文

【一步步开发AI运动APP】十二、自定义扩展新运动项目2

之前我们为您分享了【一步步开发AI运动小程序】开发系列博文,通过该系列博文,很多开发者开发出了很多精美的AI健身、线上运动赛事、AI学生体测、美体、康复锻炼等应用场景的AI运动小程序;为了帮助开发者继续深耕AI运动领域市场,今天开始我们将为您分享新系列【一步步开发AI运动APP】的博文,带您开发性能更强、体验更好的AI运动APP。

上一篇为您介绍了uni-app版运动识别插件的自定义扩展运动的基本架构、与小程序版运动识别插件的运动扩展差异,本篇我们就以双手并举为例带你来实现一个扩展运动。

一、动作姿态拆解

动作示意图

如上图所示,这个运动主要为手部摆动动,包含2个分动作姿态,起始动作姿态1为双手垂放于左右两侧站立,结束动作姿态2双手举过头顶撑直为结束动作,完成动作2时计数加一,如此反复运动。

二、定义运动检测规则

接下来我们为这两个拆解姿态分别构建检测规则,检测规则及自定义姿态的检测可以参考本系列博文的前面章节及插件的pose-calc指南文档。

  • 先构建动作姿态1手垂于两侧并站立的动作的检测规则:
 {name: '双手下垂',calc: '$and',rules: [{name: '站立姿态',calc: 'stand',offset: 25}, {name: '左腋夹角',calc: 'match-angle',angleKey: 'left_shoulder',secondKey: 'left_hip',thirdKey: 'left_wrist',angle: 30,offset: 30}, {name: '左手下垂',calc: 'vertical',upperKey: 'left_shoulder',centerKey: 'left_elbow',lowerKey: 'left_wrist',offset: 25}, {name: '右腋夹角',calc: 'match-angle',angleKey: 'right_shoulder',secondKey: 'right_hip',thirdKey: 'right_wrist',angle: 30,offset: 30}, {name: '右手下垂',calc: 'vertical',upperKey: 'right_shoulder',centerKey: 'right_elbow',lowerKey: 'right_wrist',offset: 25}]}
  • 再构建动作姿态2双手举过头顶伸直站立的检测规则:
{name: '双手上举',calc: '$and',rules: [{name: '左手上举',calc: 'position',referenceKey: 'left_eye',positionKey: 'left_wrist',position: 'top',relaxed: true}, {name: '右手上举',calc: 'position',referenceKey: 'right_eye',positionKey: 'right_wrist',position: 'top',relaxed: true}]
}

三、实现运动分析器

定义好动作姿态检测规则后,我们便可以实现此扩展运动的运动分析器了,完整代码如下:

/*** 双手并举运动分析器*/
export class BothHandsUpSport {context = null;calculator = null; //ICalculatorstateTran = -1;/*** 初始化运动分析器*/constructor() {this.calculator = createCalculator();this.buildRules();const that = this;this.context = createExtendSportContext({key: 'both-hands-up',name: '自定义-双手并举',tickMode: true,view: 'front_back',start: () => that.start(),// reset: this.reset,// stop: this.stop,pushing: human => that.pushing(human)});}buildRules() {this.rules = {};this.rules.ups = {name: '双手上举',calc: '$and',rules: [{name: '左手上举',calc: 'position',referenceKey: 'left_eye',positionKey: 'left_wrist',position: 'top',relaxed: true}, {name: '右手上举',calc: 'position',referenceKey: 'right_eye',positionKey: 'right_wrist',position: 'top',relaxed: true}]};this.rules.downs = {name: '双手下垂',calc: '$and',rules: [{name: '站立姿态',calc: 'stand',offset: 25}, {name: '左腋夹角',calc: 'match-angle',angleKey: 'left_shoulder',secondKey: 'left_hip',thirdKey: 'left_wrist',angle: 30,offset: 30}, {name: '左手下垂',calc: 'vertical',upperKey: 'left_shoulder',centerKey: 'left_elbow',lowerKey: 'left_wrist',offset: 25}, {name: '右腋夹角',calc: 'match-angle',angleKey: 'right_shoulder',secondKey: 'right_hip',thirdKey: 'right_wrist',angle: 30,offset: 30}, {name: '右手下垂',calc: 'vertical',upperKey: 'right_shoulder',centerKey: 'right_elbow',lowerKey: 'right_wrist',offset: 25}]};}start() {this.stateTran = -1;console.log('运动启动', this);}pushing(fragment) {if (fragment.isNobody) {console.log('未识别到人体');return;}const human = fragment.human;if (this.stateTran != 1 && this.calculator.calculating(human, this.rules.downs)) {this.stateTran = 1;return;}if (this.stateTran == 1 && this.calculator.calculating(human, this.rules.ups)) {this.stateTran = 2;this.context.countTimes();this.context.emitTick(1);}}/*** 获取当前扩展运动的原生分析器实例* @returns 原生运动分析器实例*/getSportInstance() {return this.context.getSport();}/*** 获取当前扩展运动描述* * @returns  运动描述条目实例*/static getDescriptor() {let item = {key: 'both-hands-up',name: '自定义-双手并举'};return item;}
}

好了,本节就为您介绍到这,下一节我们将为您介绍将实现的自定义扩展运动列表的维护,敬请期待...

image

http://www.hskmm.com/?act=detail&tid=27091

相关文章:

  • 2025 年最新真石漆厂家排行榜:别墅外墙 / 专业仿砖 / 天然涂料优质厂家最新推荐指南
  • if 和 else 的用法
  • The 4th Universal Cup
  • 18、更改公司电脑wifi密码
  • 有难度哦/Qt基于通用地图组件实现航迹规划和模拟/动态标注轨迹线/带序号和方向箭头指示
  • 【GitHub每日速递 251009】AI时代必备!Stagehand浏览器自动化框架解锁高效新玩法
  • iOS应用商店遭遇首次大规模恶意软件攻击
  • VMware ESXi 9.0.1.0 macOS Unlocker OEM BIOS 2.7 集成网卡驱动和 NVMe 驱动 (集成驱动版)
  • vue3使用ts传参教程
  • 解密prompt系列61. 手搓代码沙箱与FastAPI-MCP实战
  • MySQL 高可用构建方案详解
  • VMware ESXi 9.0.1.0 macOS Unlocker OEM BIOS 2.7 标准版和厂商定制版
  • 多机器人协同首现基础模型技术突破
  • PHP 图像处理实战 GD/Imagick 从入门到精通,构建高性能图像服务
  • 2025氧化镁厂家、活性氧化镁厂家、肥料级氧化镁厂家最新推荐榜:实力生产与优质供应之选
  • 2025学校家具定制厂家/书包柜厂家推荐榜:专业设计与安全品质首选
  • 2025农机带厂家最新推荐榜:质量可靠与耐用性能兼备之选
  • 2025深圳电源适配器厂家最新推荐榜:高效耐用与安全认证深度解析
  • 2025试验机厂家最新推荐榜:精准测量与高效检测口碑之选
  • 2025喷砂厂家 / 热喷锌厂家 / 热喷铝厂家 / 油漆涂装厂家 / 热喷耐磨材料厂家 / 防腐工程厂家最新推荐榜:高效作业与优质工艺口碑之选
  • 2025上海经济纠纷律师/民事纠纷律所最新推荐榜:专业辩护与胜诉保障口碑之选
  • Semantic Kernel + AutoGen = 开源 Microsoft Agent Framework
  • 读技术之外:社会联结中的人工智能04数据
  • Potplayer Official Download LINK
  • 二廿计划(25.10.09 - 25.10.29)
  • 生成式AI与计算教育融合研究
  • 博科SAN switch 所有端口的led闪橙色
  • 251008
  • 2025年R系列斜齿轮减速机厂家最新推荐:R系列斜齿轮减速机/F系列平行轴齿轮减速机/K系列螺旋斜齿轮减速机/S系列蜗轮减速机实力厂家精准传动解决方案
  • 2025化工泵厂家权威推荐榜:磁力泵/多级泵/高温泵/混流泵/浆液泵/螺杆泵/陶瓷泵/脱硫泵/旋涡泵/液下泵/轴流泵/自吸泵厂家,高效节能与耐用品质实力之选