【一步步开发AI运动APP】六、运动计时计数能调用

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

通过前几篇博文,您已经可以通过插件在APP上进行抽帧、人体检测了,在获得到人体结构后,便可以进行运行分析实现人体计时计数了,uniAPP插件同微信小程序一样,仍然内置了跳绳、开合跳、俯卧撑、仰卧起坐、深蹲(深蹲起)、平板支撑、马步蹲 等多个常见运动,可以满足健身、线上赛事、学生体测等场景需求,若有个性运动定制需求,也可以使用插件提供的pose-calc姿态分析检测接口,进行自定义扩展,后续章节再向您介绍。

一、创建运动分析器

通过createSport(key string)可以创建相应的运动实例:

javascript 复制代码
import {getSports,createSport} from "@/uni_modules/yz-ai-sport";

function createSport(){
	//获取已注册的所有运动列表
	let sports = getSports();
	console.log(sports);
	
	//创建了一个开合跳运动分析器
	const sport = createSport('jumping-jack');
}

二、进行运动分析,监听计数变化

启动运动分析,并向运动分析器推送人体结构,即可开展运动分析进行计时计数:

javascript 复制代码
import {getSports,createSport} from "@/uni_modules/yz-ai-sport";

function createSport(){

	//创建了一个开合跳运动分析器
	const sport = createSport('jumping-jack');
	sport.onTick = (counts,times)=>{
		//当计时计数发生变化时,会触发onTick回调
		console.log(counts,times);
		//更新UI等操作
	};
	sport.start();//启动运动分析
	
	let human = ... //见前一节,进行人体识别
	sport.pushing(human);
}

三、停止、重置运动分析

可以调用sport.stop()停止或暂停运动分析,sport.reset()重置计数状态。

四、完整代码

html 复制代码
<template>
		<yz-ai-camera class="camera" :style="{width:previewWidth,height:previewHeight}" :device="cameraDevice"
			resolution="medium" @on-camera-ready="onCameraReady" />
		<yz-pose-grapher ref="grapher" class="grapher" :style="{width:previewWidth,height:previewHeight}"
			:scaleRate="previewRate" :offsetX="previewOffsetX" :offsetY="previewOffsetY" lineColor="#FFFFFF"
			pointColor="#0091ff" leftColor="#009d00" />
</template>
<script>

import {getCameraContext,createHumanDetector,getSports,createSport} from "@/uni_modules/yz-ai-sport";

let cameraContext;
let sport;

export default {
	data(){
		return {};
	}
	methods:{
		onCameraReady(){
			cameraContext = getCameraContext();
			sport = createSport('jumping-jack');
			sport.onTick=(counts,times)=>{
				console.log(counts,times);
			};
			soprt.start();
		},
		onDetecting(){
			let options = {
				multiple: false,
				enabledGPU: true,
				highPerformance: false
			};
			humanDetector = createHumanDetector(options);
			humanDetector.startExtractAndDetect({
				onDetected(result){
					let humans = result.humans;
					this.$refs.grapher.drawing(humans);
					
					sport.pushing(humans[0]);
				}
			});
		}
	}
}
</script>
相关推荐
回眸&啤酒鸭18 小时前
【回眸】Minicart 电商购物车核心功能落地指南
人工智能
一隅论数智18 小时前
给AI一张“业务概念地图“:本体如何从哲学走向企业智能
大数据·人工智能·经验分享·笔记·学习·学习方法·政务
AI的探索之旅18 小时前
97 个 OpenCV 实例(三十):双目立体,从标定到点云
人工智能·opencv·计算机视觉
AlbertZein18 小时前
Step-5-Preview 上手实测:3D 游戏、金融分析、网页设计一次跑完
人工智能·aigc
LaughingZhu18 小时前
Product Hunt 每日热榜 | 2026-09-19
人工智能·深度学习·神经网络·搜索引擎·百度
美狐美颜SDK开放平台19 小时前
开发直播APP时如何接入视频美颜SDK?开发流程与注意事项
android·人工智能·计算机视觉·音视频·直播美颜sdk
wukangjupingbb19 小时前
智能网联汽车安全能力框架
人工智能
龙亘川19 小时前
明月照湾区,智启新赛道:从顶流文旅IP盛会看智慧文旅升级路径
人工智能·智慧城市·开源软件·数据可视化
飞猫的边缘AI20 小时前
边缘AI应用:家用AI摄像头怎么做数据训练?
人工智能·边缘计算·ai算法·边缘ai