简体   繁体   中英

Issue with Kinect V2 Coordinate Mapper

I'm currently undertaking a university project that involves object detection and recognition with a Kinect. Now I'm using the MapDethFrameToColorSpace method for coordinating the depth to rgb. I believe the issue is to with this loop here

 for (int i = 0; i < _depthData.Length; ++i)
 {
 ColorSpacePoint newpoint = cPoints[i];
 if (!float.IsNegativeInfinity(newpoint.X) && !float.IsNegativeInfinity(newpoint.Y))
 int colorX = (int)Math.Floor(newpoint.X + 0.5);
 int colorY = (int)Math.Floor(newpoint.Y + 0.5);
 if ((colorX >= 0) && (colorX < colorFrameDescription.Width) && (colorY >= 0) && (colorY < colorFrameDescription.Height))
{
       int j = ((colorFrameDescription.Width * colorY) + colorX) * bytesPerPixel;
        int newdepthpixel = i * 4;
        displaypixel[newdepthpixel] = colorpixels[(j)]; //B
        displaypixel[newdepthpixel + 1] = colorpixels[(j + 1)]; //G
        displaypixel[newdepthpixel + 2] = colorpixels[(j + 1)]; //R
        displaypixel[newdepthpixel + 3] = 255;                 //A*/
}

It appears that the indexing is not correct or there are pixels/depth values missing because the output appears to be multiples of the same image but small and with a limited x index. http://postimg.org/image/tecnvp1nx/

Let me guess: Your output image ( displaypixel ) is 1920x1080 pixels big? (Though from the link you posted, it seems to be 1829×948?)

That's your problem. MapDethFrameToColorSpace returns the corresponding position in the color image for each depth pixels. That means, you get 512x424 values. Putting those into a 1920x1080 image means only about 10% of the image is filled, and the part that's filled will be jumbled.

If you make your output image 512x424 pixels big instead, it should give you an image like the second on in this article .

Or you could keep your output image at 1920x1080, but instead of putting one pixel after the other, you'd also calculate the position where to put the pixel. So instead doing

int newdepthpixel = i * 4;

you'd need to do

int newdepthpixel =  ((colorFrameDescription.Width * colorY) + colorX) * 4;

That would give you a 1920x1080 image, but with only 512x424 pixels filled, with lots of space in between.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM