我使用 Kinect v2 和 C# 进行了一些尝试,并尝试获得一个 512x424 像素大小的图像数组,其中包含深度数据以及相关颜色信息 (RGBA)。
因此,我使用该MultiSourceFrameReader
课程接收 a MultiSourceFrame
,从中获得了ColorFrame
and DepthFrame
。通过这些方法ColorFrame.CopyConvertedFrameDataToArray()
,DepthFrame.CopyFrameDataToArray()
我收到了包含颜色和深度信息的数组:
// Contains 4*1920*1080 entries of color-info: BGRA|BGRA|BGRA..
byte[] cFrameData = new byte[4 * cWidth * cHeight];
cFrame.CopyConvertedFrameDataToArray(cFrameData, ColorImageFormat.Bgra);
// Has 512*424 entries with depth information
ushort[] dFrameData = new ushort[dWidth* dHeight];
dFrame.CopyFrameDataToArray(dFrameData);
现在我必须将位于 ColorFrame-data-array 中的颜色四元组映射到 DepthFrame-data-arraycFrameData
的每个条目,dFrameData
但这就是我卡住的地方。输出应该是一个数组,它是数组大小的 4 倍 (RGBA/BGRA),dFrameData
并且包含深度帧每个像素的颜色信息:
// Create the array that contains the color information for every depth-pixel
byte[] dColors = new byte[4 * dFrameData.Length];
for (int i = 0, j = 0; i < cFrameData.Length; ++i)
{
// The mapped color index. ---> I'm stuck here:
int colIx = ?;
dColors[j] = cFrameData[colIx]; // B
dColors[j + 1] = cFrameData[colIx + 1]; // G
dColors[j + 2] = cFrameData[colIx + 2]; // R
dColors[j + 3] = cFrameData[colIx + 3]; // A
j += 4;
}
有没有人有什么建议?
我还查看了 Kinect-SDK 的 CoordinateMappingBasics 示例,但他们对我已经开始工作的 1920x1080 像素大小的图像进行了反之亦然。
编辑
我认识到我应该能够通过使用ColorSpacePoint
包含特定颜色像素的 X 和 Y 坐标的 -struct 来获取映射的颜色信息。因此,我设置了诸如..
// Lookup table for color-point information
ColorSpacePoint[] cSpacePoints = new ColorSpacePoint[dWidth * dHeight];
this.kinectSensor.CoordinateMapper.MapDepthFrameToColorSpace(dFrameData, cSpacePoints);
.. 并尝试访问颜色信息,如 ..
int x = (int)(cSpacePoints[i].X + 0.5f);
int y = (int)(cSpacePoints[i].Y + 0.5f);
int ix = x * cWidth + y;
byte r = cFrameData[ix + 2];
byte g = cFrameData[ix + 1];
byte b = cFrameData[ix];
byte a = cFrameData[ix + 3];
..但我仍然得到错误的颜色。大多是白色的。