您的位置:首页 > 其它

基于Kinect手势跟踪和识别

2014-04-16 10:23 633 查看
 很多童鞋都在做kinect的手势识别,本人也基于kinect实现手势的跟踪和识别,跟踪过程比较稳定,几乎与OpenNI提供的SDK相当。手势的识别由于距离的原因尚不稳定,特别是当距离超过超过2.5米时。现在将手势跟踪主要代码提出来供大家参考!

XnPoint3D HandTrack(U16 *depIn, XnPoint3D handPrev)
{
XnPoint3D handCurr = handPrev;
XnPoint3D hArmPoint = {0};
XnPoint3D hFingerPoint = {0};
XnPoint3D handPred = {0};
static int handLostCnt = 0;
extern int trackFrmCnt;

if(handTrackCnt == 0)
{
handDiff.X = handDiff.Y = handDiff.Z = 0;
if(!handDiffMap)
handDiffMap = cvCreateImage(cvSize(640,480) ,IPL_DEPTH_8U, 1);
}
handTrackCnt ++;
handPred = HandPrediction(depIn,handPrev,kp);
if(handPred.Z!= 0)
{
handSharpArea = 0;
int radius = 240;

hArmPoint = GetHandSharp(depIn,handPred,radius,kp);
if(hArmPoint.Z!= 0)
{
hFingerPoint = GetFingerPoint(depIn,hArmPoint);
if(hFingerPoint.Z==0)
{
hFingerPoint = handPred;
bDirectionForward = true;
}
else
{
bLostHand = false;
int ZDiff = hFingerPoint.Z-hArmPoint.Z;
if(ZDiff>150 )
{
bDirectionForward = false;
}
}
}
else
{
hFingerPoint = handPred;
bDirectionForward = true;
}
handCurr = GetPalmPoint(depIn,hFingerPoint,90);
double dist = GetDist(handPrev,handCurr);
if((dist>TRACK_DIST && bHandPrevPred ) || (handSharpArea>TRACK_AREA))
{
bLostHand = true;
handCurr = handPrev;
}
}
else
{
handCurr = handPrev;
}
handDiff.X = handCurr.X - handPrev.X;
handDiff.Y = handCurr.Y - handPrev.Y;
handDiff.Z = handCurr.Z - handPrev.Z;
handPrev = handCurr;
memcpy(depPrev,depIn,sizeof(depPrev));
handCurr=TrackingSmoothing(handCurr,false);
return handCurr;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: