Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am trying out something with Kinect sensor. I am trying to display objects at certain depth in original colour and the rest in black. I don't want to use the playerindexbitmask since I don't want to use it for skeletons. What I have now is helping me display the original colour at the depth (between 0.5 and 2.5 meters) I specified, but I am not sure how to black out the rest of the image. Here's the code that I use right now. Thanks for any inputs. If you have any better method, please feel free to share as well.

C#
ColorImageFrame cframe4 = _sensor.ColorStream.OpenNextFrame(0);
DepthImageFrame dframe4 = _sensor.DepthStream.OpenNextFrame(0);
byte[] pixeldata = new byte[cframe4.PixelDataLength];
cframe4.CopyPixelDataTo(pixeldata);
int vx,vy;

DepthImagePixel[] pixeldata4 = new DepthImagePixel[dframe4.PixelDataLength];
dframe4.CopyDepthImagePixelDataTo(pixeldata4);

for (int y = 0; y < dframe4.Height; y++)
                {
                    for (int x = 0; x < dframe4.Width; x++)
                    {
			ColorImagePoint p = dframe4.MapToColorImagePoint(x, y, ColorImageFormat.RgbResolution640x480Fps30);

			vx = p.X;
                        vy = p.Y;

                        int d = pixeldata4[x + y * dframe4.Width].Depth;

                        vx = Math.Max(0, Math.Min(vx, cframe4.Width - 2));
                        vy = Math.Max(0, Math.Min(vy, cframe4.Height - 2));


                            if (d > 500 && d < 2500)
                            {
                                pixeldata[(vx + vy * cframe4.Width) * cframe4.BytesPerPixel] &= 0xFF;
                            }
                            else
                            {
                                 //not sure what to insert in order to blank out the pixels without any data. ANDing with 0x00 results in yellow colour mask on top of original image, but not blank image                            
                            }
                        }
                   
                }
Bitmap bmp = ByteToBitmap(pixeldata, cframe4.Width, cframe4.Height);
image1.Source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(bmp.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
bmp.Dispose();
Posted
Updated 14-May-13 18:54pm
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900