0

我对 Kinect v2 CoordinateMapper API 感到困惑。我想在 Kinect v2中获取每个 3D 点(即CameraSpacePoint )的 RGB 值。

请看下面的代码片段:

var depthFrame = multiSourceFrame.DepthFrameReference.AcquireFrame();
var colorFrame = multiSourceFrame.ColorFrameReference.AcquireFrame();

var depthWidth = depthFrame.FrameDescription.Width;
var depthHeight = depthFrame.FrameDescription.Height;

ushort[] depthData = new ushort[depthWidth * depthHeight];
CameraSpacePoint[] camerapoints = new CameraSpacePoint[depthData.Length];
ColorSpacePoint[] colorpoints = new ColorSpacePoint[depthData.Length];

depthFrame.CopyFrameDataToArray(depthData);
this.coordinateMapper.MapDepthFrameToCameraSpace(depthData, camerapoints);
this.coordinateMapper.MapDepthFrameToColorSpace(depthData, colorpoints);

3D 点存储在camerapoints变量中。我想要每个 RGB 值camerapoints。换句话说,请看下面的伪代码:

RGBPoint[] rgbpoints = new RGBPoint[depthData.Length];
RGBPoint rgbpoint = rgbpoints[0];
int red   = rgbpoint.r
int green = rgbpoint.g
int blue  = rgbpoint.b

一如既往,非常感谢。我真的很感谢你的友好回应。

4

1 回答 1

1

colorpoints数组包含对应于depthData数组中每个像素的 (x, y) 索引。从这里,我们可以在colorFrame由 指示的每个特定 (x, y) 索引处获取颜色帧数据(来自 )colorpoints[index]

var colorWidth = colorFrame.FrameDescription.Width;
var colorHeight = colorFrame.FrameDescription.Height;

// Assuming BGRA format here
byte[] pixels = new byte[colorWidth * colorHeight * 4];
colorFrame.CopyFrameDataToArray(pixels);

byte[] bgraPoints = new byte[depthWidth * depthHeight * 4];

for (var index = 0; index < depthData.Length; index++)
{
    var u = colorpoints[index].X;
    var v = colorpoints[index].Y;
    if (u < 0 || u >= colorWidth || v < 0 || v >= colorHeight) continue;
    var pixelsBaseIndex = v * colorWidth + u;
    Array.Copy(pixels, 4 * pixelsBaseIndex, bgraPoints, 4 * index, 4);
}

var index = 0;
var red = bgraPoints[4 * index + 2];
var green = bgraPoints[4 * index + 1];
var blue = bgraPoints[4 * index];
于 2017-11-21T11:30:58.083 回答