我使用下面的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/