Search code examples
c#c++kinectkinect-sdk

How can I save kinect skeleton data into a file?


I was able to do this in the Kinect SDK beta 3, but I haven't developed for Kinect since and a lot seems to have changed.

I want to save each joint as a variable and write those values to a .csv file that I can parse through later. (Using c# preferably, but I can work with the c++ version as well)

Question

-What do I need to call to be able to get numerical values for each of the joints?

Any help would be appriciated!


Solution

  • The Skeleton data is just a series of Joint collections, containing X/Y/Z coordinates. You can save them and write them just like any other type of object.

    Getting the value of a Joint is shown in multiple examples provided by Microsoft for the Kinect for Windows Samples. Please explore those examples to gain a basis for working with the latest Kinect SDK.

    Here is a basic callback to parse the SkeletonFrame and work with individual skeletons:

    private void OnSkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
    {
        using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame())
        {
            if (skeletonFrame == null || skeletonFrame.SkeletonArrayLength == 0)
                return;
    
            // resize the skeletons array if needed
            if (_skeletons.Length != skeletonFrame.SkeletonArrayLength)
                _skeletons = new Skeleton[skeletonFrame.SkeletonArrayLength];
    
            // get the skeleton data
            skeletonFrame.CopySkeletonDataTo(_skeletons);
    
            foreach (var skeleton in _skeletons)
            {
                // skip the skeleton if it is not being tracked
                if (skeleton.TrackingState != SkeletonTrackingState.Tracked)
                    continue;
    
                // print the RightHand Joint position to the debug console
                Debug.Writeline(skeleton.Joints[JointType.HandRight]);
            }
        }
    }
    

    Additionally, the Kinect Toolbox comes with functions that allow you to record and replay all 3 of the streams.