When I attempt to run my skeletal tracking code to test out the following line of code I have added in, it crashes with an error.

    void sensor_AllFramesReady(object sender, AllFramesReadyEventArgs e)
    {
        if (closing)
        {
            return;
        }

        //Get a skeleton
        Skeleton first = GetFirstSkeleton(e);

        if (first == null)
        {
            return;
        }


        using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame())
        {
            //if (skeletonFrame == null)
            //{
            //    return;
            //}
            this.recordStream = new MemoryStream(100);
            KinectRecorder Recorder = new KinectRecorder(KinectRecordOptions.Skeletons, recordStream);
            if (skeletonFrame != null)
            {
                this.Recorder.Record(skeletonFrame);
            }
            //StartRecord
           // Skeleton[] skeletonData = this.Recorder.Record(skeletonFrame);

        }
 // some more stuff
 }

I am calling the Record function available in the Kinect Toolbox.

The error is: System.NullReferenceException was unhandled ....... Message=Object reference not set to an instance of an object. ..... Source=SkeletalTracking

Update: If I have moved the initialization into the same function as the call of the recorder.

有帮助吗?

解决方案

Based on the code you've posted, you never initialize your KinectRecorder.

this.Recorder.Record(skeletonFrame); // I get an error after the RGB camera view freezes

... would produce a null pointer, because Recorder was never initialized. Unless you've left that part out of your code example here. You can do it at the time you declare it, or later if you prefer.

KienctRecorder Recorder = new KinectRecorder(options, stream);

options need to be set up for your appropriate KinectRecordOptions. stream is your output Stream.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top