Kinect Null Depth and Color Frame

I am developing a game using XNA Framework 4.0

and Kinect 1.6 SDK

. My code uses color, depth and skeleton data, so I am using event AllFramesReady

.

When I start the game and someone detects, the event called function AllFramesReady

retrieves the image and skeleton data of the person and sets the attributes of my class Player

.

The problem is that this code has worked fine in the past. But even if I didn't make any changes to my code, it doesn't work now. I tried on other computers and it worked. But the same code doesn't work on my computer.

When I debugged I saw that DepthFrameEventReadyArgs

both ColorFrameEventReadyArgs

have a member named isInvalid

and they are set to true. Because of this, when I use:

DepthImageFrame depthVideoFrame = mainFrame.OpenDepthImageFrame();

... I am getting null depthVideoFrame

. The same goes for the color frame.

Here's how I initialize the Kinect (in Initialize

):

if (KinectSensor.KinectSensors.Count > 0)
            {
                kinect = KinectSensor.KinectSensors[0];

                EnableColorStream(kinect);
                EnableDepthStream(kinect);
                EnableSkeletonStream(kinect);

                kinect.AllFramesReady += new EventHandler<AllFramesReadyEventArgs>(kinect_AllFramesReady);
                kinect.Start();
            }

      

Include methods:

void EnableColorStream(KinectSensor ks)
        {
            ks.ColorStream.Enable(ColorFormat);
            colorWidth = ks.ColorStream.FrameWidth;
            colorHeight = ks.ColorStream.FrameHeight;
            colorVideo = new Texture2D(graphics.GraphicsDevice, ks.ColorStream.FrameWidth, ks.ColorStream.FrameHeight);
        }

        void EnableDepthStream(KinectSensor ks)
        {
            ks.DepthStream.Enable(DepthFormat);
            depthWidth = ks.DepthStream.FrameWidth;
            depthHeight = ks.DepthStream.FrameHeight;
            depthVideo = new Texture2D(graphics.GraphicsDevice, ks.DepthStream.FrameWidth, ks.DepthStream.FrameHeight);
        }

        void EnableSkeletonStream(KinectSensor ks)
        {
            TransformSmoothParameters tsp = new TransformSmoothParameters();
            tsp.Smoothing = 0f;
            tsp.Correction = 0.1f;
            tsp.Prediction = 0.1f;
            tsp.JitterRadius = 0.1f;
            tsp.MaxDeviationRadius = 0.1f;
            ks.SkeletonStream.Enable(tsp);
        }

      

In kinect_AllFramesReady

I am using something like:

using (ColorImageFrame colorVideoFrame = imageFrames.OpenColorImageFrame())
{
   ...
}
using (SkeletonFrame skeletonFrame = imageFrames.OpenSkeletonFrame())
{
   ...
}
using (DepthImageFrame depthVideoFrame = imageFrames.OpenDepthImageFrame())
{
   ...
}

      

As I debug, I saw that the values were colorVideoFrame

and depthVideoFrame

were null

because the element was isInvalid

set to a value true

. When I run other programs using the depth and color data, they work fine, but this one doesn't. I am currently out of ideas. Thanks for any help.

+3


source to share


1 answer


Perhaps you could try. As one commenter said, you can get this error since you only ever call AllFramesReady. You may need to call it in the SkeletonFrame, ColorFrame, and DepthFrameReady event handlers. Example.

void DepthFrameReady(object sender, DepthImageFrameReadyEventArgs e)
{
 DepthImageFrame imageFrame = e.OpenDepthImageFrame();
 if (imageFrame != null)
 {
   // Do your business here
 }
}

      



The reason I'm going to answer this question is because the Kinect for Windows SDK documentation says "Color data frame in new ColorImageFrame, or NULL if data is no longer available." and since your machine might be configured differently than other machines your code was running on, any changes to the K4WSDK or your compiler could dramatically change the way your program works after it has been compiled.

As far as it doesn't work, it could be a compiler issue on your computer. Have you checked that you have the same compiler version in VS? Is this the VS version? Also, have you verified that all relevant libraries and their applications are present on your computer? If you really want to determine the root cause, you can go to work machines and compare them to your own.

0


source







All Articles