选择左右手是通过,一开始我们在Psi姿势识别人体,然后摆动需要控制的手,完成左右手选择。
void SelectHand()
{
if (selectHand)
{
putText(cvBGRImage,"Please select your control hand!",Point(320,240),1,1,Scalar(255,255,255));
if (abs(imagepointReal[0].X-imagepointReal[2].X)>abs(1.5*(imagepointReal[8].X-imagepointReal[2].X)))
{
isLeft=true;
selectHand=false;
}
if (abs(imagepointReal[1].X-imagepointReal[3].X)>abs(1.5*(imagepointReal[7].X-imagepointReal[3].X)))
{
isRight=true;
selectHand=false;
}
}
}
然后通过winapi进行鼠标的控制
void MouseMove()
{
if (isLeft)
{
int CursorPox_X=(int)((imagepoint[0].X/640)*ScreenRes_X+100);
int CursorPox_Y=(int)((imagepoint[0].Y/480)*ScreenRes_Y+50);
SetCursorPos(CursorPox_X,CursorPox_Y);
}
if (isRight)
{
int CursorPox_X=(int)((imagepoint[1].X/640)*ScreenRes_X+100);
int CursorPox_Y=(int)((imagepoint[1].Y/480)*ScreenRes_Y+50);
SetCursorPos(CursorPox_X,CursorPox_Y);
}
}
不过,这种方法鼠标抖动比较厉害,后面会利用NITE再进行优化