麻烦读kinect的骨架

时间:2013-04-11 18:48:38

标签: c# kinect kinect-sdk

我是kinect编程的新手,我正在尝试绘制骨架并且它无法正常工作我正在使用1.6版本的kinect sdk并且我的代码运行但是当它到达此部分时它会停止:

void kinectsensor_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
        {
           SkeletonFrame skeletonSet = e.OpenSkeletonFrame();

     //   Skeleton skeletonData = new Skeleton[kinectsensor.SkeletonStream.FrameSkeletonArrayLength];

        **Skeleton skeletonData = (from s in skeletons
                             where s.TrackingState == SkeletonTrackingState.Tracked
                             select s).FirstOrDefault();**
        if (skeletonData != null)


        {
            SetEllipsePosition(Head, skeletonData.Joints[JointType.Head]);
            SetEllipsePosition(leftHand, skeletonData.Joints[JointType.HandLeft]);
            SetEllipsePosition(rightHand, skeletonData.Joints[JointType.HandRight]);
            ProcessGesture(skeletonData.Joints[JointType.Head], skeletonData.Joints[JointType.HandLeft], skeletonData.Joints[JointType.HandRight]);
        }
    }

我得到的警告信息是:

  

永远不会分配'KinectSkeletonApplication3.MainWindow.skeletons'   to,并且将始终具有其默认值null

2 个答案:

答案 0 :(得分:0)

我对Kinect的编程知之甚少,但你需要从某些东西中分配骨架数组,可能使用copySkeletonDataTo()

答案 1 :(得分:0)

典型的SkeletonFrameReady回调如下所示:

private Skeleton[] skeletonData;

private void SkeletonsReady(object sender, SkeletonFrameReadyEventArgs e)
{
    using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame())
    {
        if (skeletonFrame != null)
        {
            int skeletonSlot = 0;

            if ((this.skeletonData == null) || (this.skeletonData.Length != skeletonFrame.SkeletonArrayLength))
            {
                this.skeletonData = new Skeleton[skeletonFrame.SkeletonArrayLength];
            }

            skeletonFrame.CopySkeletonDataTo(this.skeletonData);

            foreach (Skeleton skeleton in this.skeletonData)
            {
                if (SkeletonTrackingState.Tracked == skeleton.TrackingState)
                {
                    // `skeleton` is an actively tracked skeleton
                }
            }
        }
    }
}

您可以在Kinect for Windows Developer ToolkitKinect for Windows CodePlex网站上找到许多相关示例。