随着深度学习推理技术的不断发展,让小型设备运行深度学习成为可能,阿里体育等IT大厂,推出的“乐动力”、“天天跳绳”AI运动APP,让云上运动会、线上运动会、健身打卡、AI体育指导等概念空前火热。那么,能否将这些在APP成功应用的场景搬上微信小程序,分享这些概念的红利呢?本系列文章就带您一步一步从零开始开发一个AI运动小程序,本系列文章将使用“AI运动识别”小程序插件,插件详情可以前往微信服务市场搜索相应插件。
在进行运动和姿态识别时,离摄像头太近,则无法取得全身关键点;若离摄像头太远,则人体图像太小,关键点将混成一团,识别效果太差,如下图所示:
基于此,就非常有必要在正式开始运动前,对人体站位进行预检,再通过语音等方式提醒用户调整站位至合适距离,以便获得最佳体验和识别效果,我们建议将人体控制在帧图像的55%-85%
之间。
whole
检测规则
whole
是插件姿态计算引擎body-calc
提供检测整个人体是否全部位于帧图像(或指定的范围)内,我们可以利用此规则进行人体远近的检测,如果人体只有部分在帧图像的85%范围内(whole执行结果为false
)则表示站得太近了;如果人体全部在帧图像的55%范围内(whole执行结果为true
)则表示离得太远了。
近
判断在进行远近判断前,请查阅本系列博文了解抽帧、人体识别、body-calc应用等内容。
const AiSport = requirePlugin("aiSport");
const humanDetection = AiSport.humanDetection;
const Calculator = AiSport.calc.Calculator;
const RANGE = 0.85; //人体必须在帧图像中间85%区域内
const rule = {
name: '人体太近检查',
calc: 'whole',
range: {
top: 0,
left: 0,
width: 0,
height: 0
},
relaxed: true
};
const calculator = new Calculator();
//抽帧
const context = wx.createCameraContext();
const listener = context.onCameraFrame((frame) => {
const iamge = {
width: Number(frame.width),
height: Number(frame.height),
rawData: frame.data
};
rule.range.top = frame.height * (1 - RANGE) / 2;
rule.range.left = frame.width * (1 - RANGE) / 2;
rule.range.height = frame.height * RANGE;
rule.range.width = frame.width * RANGE;
//人体识别
humanDetection.detectionAsync(image).then(human=>{
//执行检测
if(!calculator.calculating(human, rule)){
console.log('站得太近了,请远离');
//播放语音、UI提示...
return;
}
//通过,则进入运动检测等应用环节..
});
});
listener.start();
远
判断const AiSport = requirePlugin("aiSport");
const humanDetection = AiSport.humanDetection;
const Calculator = AiSport.calc.Calculator;
const RANGE = 0.55; //人体必须在帧图像中间55%区域以外
const rule = {
name: '人体远离检查',
calc: 'whole',
range: {
top: 0,
left: 0,
width: 0,
height: 0
},
relaxed: true
};
const calculator = new Calculator();
//抽帧
const context = wx.createCameraContext();
const listener = context.onCameraFrame((frame) => {
const iamge = {
width: Number(frame.width),
height: Number(frame.height),
rawData: frame.data
};
rule.range.top = frame.height * (1 - RANGE) / 2;
rule.range.left = frame.width * (1 - RANGE) / 2;
rule.range.height = frame.height * RANGE;
rule.range.width = frame.width * RANGE;
//人体识别
humanDetection.detectionAsync(image).then(human=>{
//执行检测
if(calculator.calculating(human, rule)){
console.log('站得太远了,请近些');
//播放语音、UI提示...
return;
}
//通过,则进入运动检测等应用环节..
});
});
listener.start();
好了,远近检测就为您介绍到这,下篇将带您进行站力视角检查,敬请期待...
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。