0

我是 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' 从未分配给,并且始终具有其默认值 null

4

2 回答 2

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站点中找到许多这样的示例。

于 2013-04-12T00:54:18.613 回答
0

我对 Kinect 的编程了解不多,但是您需要从某些东西中分配骨架数组,也许使用copySkeletonDataTo()

于 2013-04-11T19:19:16.543 回答