How to convert ColorImageFormat.InfraredResolution640x480Fps30 to System.Drawing.Bitmap RRS feed

  • Question

  • Hi,

    I initialize my Kinect sensor's Color stream to return InfraRed images:


    Then once I receive a ColorImageFrame I convert the ColorImageFrame to a bitmap:

    private static Bitmap ColorImageFrameToBitmap(ColorImageFrame colorFrame)
        byte[] pixelBuffer = new byte[colorFrame.PixelDataLength];
        PixelFormat pixelFormat = PixelFormat.Format32bppRgb;
        if (colorFrame.Format == ColorImageFormat.InfraredResolution640x480Fps30)
            pixelFormat = PixelFormat.Format16bppRgb565;
        Bitmap bitmapFrame = new Bitmap(colorFrame.Width, colorFrame.Height, pixelFormat);
        BitmapData bitmapData = bitmapFrame.LockBits(frameRectangle, ImageLockMode.WriteOnly, bitmapFrame.PixelFormat);
        IntPtr intPointer = bitmapData.Scan0;
        Marshal.Copy(pixelBuffer, 0, intPointer, colorFrame.PixelDataLength);
        bitmapData = null;
        pixelBuffer = null;
        return bitmapFrame;

    The problem I'm having is that infrared images appear to always have a shadow, also being very grainy. I'm not too clued up when it comes to image conversion :) I know its possible using WPF code, but in this instance I'd prefer a Windows Forms based implementation. Any ideas on what I've missed?

    Thanks in advance,

    Dewald Esterhuizen


    It's like software, by default - Just me taking a jab at people who pronounce my name wrong :) Have a look at my blog - Open source all the way or get me on twitter @DefaultSoftware

    Friday, February 22, 2013 1:08 AM


  • The infrared image data is a 16-bit monochrome intensity value, not an RGB color value. Replace ColorFormat.Format16bppRgb565 with ColorFormat.Format16bppGrayScale.

    The grain and the shadow you've observed are artifacts of the Kinect depth sensor, which emits a structured IR light pattern into your scene. The grain is the IR light pattern itself. The shadow is due to the horizontal separation between the IR emitter and the IR camera: the camera can see some parts of the scene that the emitter doesn't reach, and these areas appear as shadows.

    If you want, you can turn off the IR emitter and use your own external IR light source(s) instead. Turn off the IR emitter by setting KinectSensor.ForceInfraredEmitterOff to true. Note that while the emitter is off, the Kinect sensor will be unable to track depth or skeletons.

    John | Kinect for Windows development team

    Thursday, February 28, 2013 1:49 AM