c++ - 翻转从 Kinect 收到的深度帧

标签 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;

    }

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

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

最佳答案

因此,您正在使用标准的 16bpp 单 channel 深度图和播放器数据。这是一种非常容易使用的格式。图像缓冲区按行排列,图像数据中的每个像素的低 3 位设置为播放器 ID,高 13 位设置为深度数据。

这是一种快速的'n'dirty 方法,可以反向读取每一行,并将其写入具有简单深度可视化的 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;
    }
}

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

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

关于c++ - 翻转从 Kinect 收到的深度帧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13193607/

相关文章:

C++ Getline 问题(没有重载函数的实例 "getline"

c++ - 在 MSVC 2010 上 boost STATIC_ASSERT

c++ - 导入库如何工作?详情?

visual-studio-2010 - 构建时被另一个进程锁定的输出文件

c# - 将 kinect 骨架位置数据传递到另一个窗口

c++ - 允许结构内部的静态断言吗?

C++ 单元测试 : Stubs (not mocks)?

c++ - Windows 错误报告何时创建转储文件?它是可配置的吗?这在 Windows 7 中有变化吗?

具有显式派生方法的 C++ 接口(interface)

物体体积计算/估计