12

我使用 Kinect v2 和 C# 进行了一些尝试,并尝试获得一个 512x424 像素大小的图像数组,其中包含深度数据以及相关颜色信息 (RGBA)。

因此,我使用该MultiSourceFrameReader课程接收 a MultiSourceFrame,从中获得了ColorFrameand 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];

..但我仍然得到错误的颜色。大多是白色的。

4

1 回答 1

3

嗯,我自己想通了。这个错误是微不足道的。由于该数组不是一个像素数组,其中一个条目包含 RGBA 信息,而是一个字节数组,其中每个条目代表 R、G、B 或 AI,因此必须将索引乘以每像素字节值,在这种情况下为 4 .所以解决方案看起来像:

int ix = (x * cWidth + y) * 4;
byte r = cFrameData[ix + 2];
byte g = cFrameData[ix + 1];
byte b = cFrameData[ix];
byte a = cFrameData[ix + 3];
于 2018-03-26T18:49:01.650 回答