none
using BodyIndexFrame to get point cloud data RRS feed

  • Question

  • Hi, I'm new to kinect programming. I'm wondering how could i get a point cloud data using the BodyIndexFrame?

    I've looked into the BodyIndexBasics sample and i kinda wonder if i could get a point cloud data of just the body being viewed ignoring the background? and how can i save this point cloud data into a text file or other files?

    Wednesday, July 29, 2015 10:56 AM

Answers

  • Going off the top of my head right now..

    Basically your algorithm needs to get the depth of the tracked body. You can do this with the BodyIndex, if the depth pixel index has a bodyIndex then you know the depth index is matching a body. You also need to get the color pixel that matches the depth index pixel. Then you need to get where those color pixels match the cameraspace indices. Once you have that you basically draw/project the color image pixels in 3-d using the cameraspace points.


    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: http://dgoins.wordpress.com

    • Proposed as answer by angela.h [MSFT] Friday, July 31, 2015 9:44 PM
    • Marked as answer by hellcrush Friday, July 31, 2015 11:01 PM
    Thursday, July 30, 2015 10:32 PM

All replies

  • Going off the top of my head right now..

    Basically your algorithm needs to get the depth of the tracked body. You can do this with the BodyIndex, if the depth pixel index has a bodyIndex then you know the depth index is matching a body. You also need to get the color pixel that matches the depth index pixel. Then you need to get where those color pixels match the cameraspace indices. Once you have that you basically draw/project the color image pixels in 3-d using the cameraspace points.


    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: http://dgoins.wordpress.com

    • Proposed as answer by angela.h [MSFT] Friday, July 31, 2015 9:44 PM
    • Marked as answer by hellcrush Friday, July 31, 2015 11:01 PM
    Thursday, July 30, 2015 10:32 PM
  • Going off the top of my head right now..

    Basically your algorithm needs to get the depth of the tracked body. You can do this with the BodyIndex, if the depth pixel index has a bodyIndex then you know the depth index is matching a body. You also need to get the color pixel that matches the depth index pixel. Then you need to get where those color pixels match the cameraspace indices. Once you have that you basically draw/project the color image pixels in 3-d using the cameraspace points.


    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: http://dgoins.wordpress.com

    Hi, can you explain to me how can i match the color pixels with the cameraspace indices? I thought that i understand how to do it but upon trying, i couldn't really get it. 

    this is the code that i used based on the BodyIndexBasics sample.

    private void Reader_FrameArrived(object sender, BodyIndexFrameArrivedEventArgs e)
            {
                bool bodyIndexFrameProcessed = false;

                using (BodyIndexFrame bodyIndexFrame = e.FrameReference.AcquireFrame())
                {
                    if (bodyIndexFrame != null)
                    {
                        // the fastest way to process the body index data is to directly access 
                        // the underlying buffer
                        using (Microsoft.Kinect.KinectBuffer bodyIndexBuffer = bodyIndexFrame.LockImageBuffer())
                        {
                            // verify data and write the color data to the display bitmap
                            if (((this.bodyIndexFrameDescription.Width * this.bodyIndexFrameDescription.Height) == bodyIndexBuffer.Size) &&
                                (this.bodyIndexFrameDescription.Width == this.bodyIndexBitmap.PixelWidth) && (this.bodyIndexFrameDescription.Height == this.bodyIndexBitmap.PixelHeight))
                            {
                                this.ProcessBodyIndexFrameData(bodyIndexBuffer.UnderlyingBuffer, bodyIndexBuffer.Size);
                                bodyIndexFrameProcessed = true;
                            }
                        }
                    }
                }

                if (bodyIndexFrameProcessed)
                {
                    this.RenderBodyIndexPixels();
                }
            }
          
                   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,
                        // display the appropriate color
                        this.bodyIndexPixels[i] = BodyColor[frameData[i]];
                        
                    }
                    else
                    {
                        // this pixel is not part of a player
                        // display black
                        this.bodyIndexPixels[i] = 0x00000000;
                    }
                }
            }
           
            private void RenderBodyIndexPixels()
            {
                this.bodyIndexBitmap.WritePixels(
                    new Int32Rect(0, 0, this.bodyIndexBitmap.PixelWidth, this.bodyIndexBitmap.PixelHeight),
                    this.bodyIndexPixels,
                    this.bodyIndexBitmap.PixelWidth * (int)BytesPerPixel,
                    0);
            }

    From what i understand, this code should cover the first few points that you've mentioned.

    Monday, August 3, 2015 12:55 PM