翻转从Kinect收到的深度帧

mem*_*elf 0 c++ visual-c++ kinect

我使用以下c ++代码从kinect中读出深度信息:

    BYTE * rgbrun = m_depthRGBX;
    const USHORT * pBufferRun = (const USHORT *)LockedRect.pBits;

    // end pixel is start + width*height - 1
    const USHORT * pBufferEnd = pBufferRun + (Width * Height);

    // process data for display in main window.
    while ( pBufferRun < pBufferEnd )
    {
        // discard the portion of the depth that contains only the player index
        USHORT depth = NuiDepthPixelToDepth(*pBufferRun);

        BYTE intensity = static_cast<BYTE>(depth % 256);


        // Write out blue byte
        *(rgbrun++) = intensity;

        // Write out green byte
        *(rgbrun++) = intensity;

        // Write out red byte
        *(rgbrun++) = intensity;

        ++rgbrun;

        ++pBufferRun;

    }
Run Code Online (Sandbox Code Playgroud)

我想知道的是,实现帧翻转(水平和垂直)的最简单方法是什么?我在kinect SDK中找不到任何功能,但也许我错过了它?

EDIT1我不想使用任何外部库,因此非常感谢任何解释深度数据布局以及如何反转行/列的解决方案.

Roo*_*ook 5

因此,您正在使用带有播放器数据的标准16bpp单通道深度图.这是一个很好的简单格式.逐行布置图像缓冲器,并且图像数据中的每个像素具有设置为播放器ID的底部3位和设置为深度数据的顶部13位.

这是一种快速反向读取每一行的方法,并将其写入RGBWhatever图像,其中只有一个简单的深度可视化,可以更好地查看当前使用的包装输出.

BYTE * rgbrun = m_depthRGBX;
const USHORT * pBufferRun = (const USHORT *)LockedRect.pBits;

for (unsigned int y = 0; y < Height; y++)
{
    for (unsigned int x = 0; x < Width; x++)
    {
        // shift off the player bits
        USHORT depthIn = pBufferRun[(y * Width) + (Width - 1 - x)] >> 3;

        // valid depth is (generally) in the range 0 to 4095.
        // here's a simple visualisation to do a greyscale mapping, with white
        // being closest. Set 0 (invalid pixel) to black.
        BYTE intensity = 
            depthIn == 0 || depthIn > 4095 ?
                0 : 255 - (BYTE)(((float)depthIn / 4095.0f) * 255.0f);

        *(rgbrun++) = intensity;
        *(rgbrun++) = intensity;
        *(rgbrun++) = intensity;
        ++rgbrun;
    }
}
Run Code Online (Sandbox Code Playgroud)

代码未经测试,E&OE等;-)

可以并行化外部循环,如果不是使用单个rgbrun指针,而是获得指向当前行开头的指针,而是将输出写入该循环.