replacing body index pixels with an image or video. RRS feed

  • Question

  • does anybody know how to replace the body index pixels with an image or video? each time i try i get null point exception. replacing the pixels with a solid color seems to be fine though.

    here is part of my code:

            private unsafe void ProcessBodyIndexFrameData(IntPtr bodyIndexFrameData, uint bodyIndexFrameDataSize)
                byte* frameData = (byte*)bodyIndexFrameData;


                // convert body index to a visual representation
                for (int i = 0; i < (int)bodyIndexFrameDataSize; ++i)
                    // the BodyColor array has been sized to match
                    // BodyFrameSource.BodyCount
                    if (frameData[i] < BodyColor.Length)
                        // this pixel is part of a player,
                        //this.bodyIndexPixels[i] = 0x00000000;
                        this.bodyIndexPixels[i] = ImageBackground1[frameData[i]];
                        // these are background pixels
                        this.bodyIndexPixels[i] = 0x99FFFF;

            private void OpenImage()
                    String PhotoFilePath = @"C:\Users\Vlux\Desktop\kinect code\BodyIndexBasics-WPF\Images\Picture.jpg";

                    Bitmap image1 = (Bitmap)Image.FromFile(PhotoFilePath, true);

                    FileStream fs = new FileStream(PhotoFilePath, FileMode.Open, FileAccess.Read);
                    BinaryReader br = new BinaryReader(fs);

                    byte[] ImageBackground1 = br.ReadBytes((int)fs.Length); 



                catch (System.IO.FileNotFoundException)
                    MessageBox.Show("There was an error opening the bitmap." +
                        "Please check the path.");
            }//end of OpenImage();

    Monday, November 17, 2014 2:48 AM

All replies

  • Hi Vlux,

    In the C++ example this is pretty easy to do.

    Just replace the drawing buffer with your image. In the method to fill the buffer, just check to see if the pixel belongs to the user and if so, use the pixels from the pre fetched buffer to the image. The C++ Coordinate mapper sample provides you with all the code you need.

    In C# this requires a bit more code. For a WPF app you'd need to use probably 1 writable and 1 regular bitmap. One with your prefetched image (regular) and the writable bitmap to modify the buffer using the same logic above.

    Sr. Enterprise Architect | Trainer | Consultant | MCT | MCSD | MCPD | SharePoint TS | MS Virtual TS |Windows 8 App Store Developer | Linux Gentoo Geek | Raspberry Pi Owner | Micro .Net Developer | Kinect For Windows Device Developer |blog:

    Monday, November 17, 2014 5:31 PM
  • This will depend greatly on the UI framework you are planning on using. Our coordinate mapper will show how to "knock-out" the background pixels that are not part of the body index. Replacing pixels on a render surface will depend greatly on what access you have to the pixel buffer and its structure.

    based on your code what line is producing the null exception. I don't see where Kinect api's are being used? Have you followed the pattern to ensure your acquireFrame call had returned a non-null frame? Is the frame disposed?

    Carmine Sirignano - MSFT

    Monday, November 17, 2014 6:01 PM