0
votes

I'm new to kinect programming and i am trying to map a skeleton and it is not working properly i'm using the 1.6 version of kinect sdk and my code runs but when it gets to this part it stops:

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]);
        }
    }

the warning message i get is:

'KinectSkeletonApplication3.MainWindow.skeletons' is never assigned to, and will always have its default value null

2
Where is skeletons declared? It appears it is never set.Cemafor
i have skeltons declared before public MainWindow() as: KinectSensor kinectsensor = KinectSensor.KinectSensors[0]; Skeleton[] skeletons;user2271697
Do you ever assign anything to it?Cemafor
No I did not assign anything to it.user2271697
I am using Microsoft.Kinect instead of Microsoft.Research.Kinect referenceuser2271697

2 Answers

0
votes

I don't know much about programming for Kinect, but you will need to assign the skeletons array from something, perhaps using copySkeletonDataTo()

0
votes

A typical SkeletonFrameReady callback looks like this:

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
                }
            }
        }
    }
}

You can find many examples of this in the Kinect for Windows Developer Toolkit and the Kinect for Windows CodePlex site.