十五、AI运动识别中,如何判断人体站位的远近?

发布时间 2023-12-25 13:12:18作者: alphaair

【云智AI运动识别小程序插件】,可以为您的小程序,赋于人体检测识别、运动检测识别、姿态识别检测AI能力。本地原生识别引擎,无需依赖任何后台或第三方服务,有着识别速度快、体验佳、扩展性强、集成快、成本低的特点,本篇实现需要使用此插件,请先行在微信服务市场或官网了解详情。

一、为什么要判断人体与摄像头的远近?

在进行运动和姿态识别时,离摄像头太近,则无法取得全身关键点;若离摄像头太远,则人体图像太小,关键点将混成一团,识别效果太差,如下图所示:
image

基于此,就非常有必要在正式开始运动前,对人体站位进行预检,再通过语音等方式提醒用户调整站位至合适距离,以便获得最佳体验和识别效果,我们建议将人体控制在帧图像的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
	}
};
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 * RANGE / 2;
	rule.range.left = frame.width * RANGE / 2;
	rule.range.height = frame.height * RANGE;
	rule.range.widht = frame.widht * 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
	}
};
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 * RANGE / 2;
	rule.range.left = frame.width * RANGE / 2;
	rule.range.height = frame.height * RANGE;
	rule.range.widht = frame.widht * RANGE;
	
	//人体识别
	humanDetection.detectionAsync(image).then(human=>{
		
		//执行检测
		if(calculator.calculating(human, rule)){
		    console.log('站得太远了,请近些');
			//播放语音、UI提示...
			return;
		}
		
		//通过,则进入运动检测等应用环节..
	});
});
listener.start();

好了,远近检测就为您介绍到这,下篇将带您进行站力视角检查,敬请期待...