我正在开展一个关于使用kinect进行生物识别测量的项目。我有一个Xbox的Kinect v1。我可以通过这个kinect获得彩色图像和深度图像。我想映射彩色图像点的深度值。 Kinect sdk不支持CoordinateMapper.MapColorPoint2DepthPoint或空格。 所有坐标转换方法都在这里。All Mapping Functions List
如何使用kinect v1为xbox将色点映射到深度点。 谢谢你的回答。
注意:语言:C#,平台:Windows表单
答案 0 :(得分:1)
您需要的是CoordinateMapper.MapDepthFrameToColorFrame
method。
Coordinate Mapping Basics-WPF C# Sample显示了如何使用此方法。您可以在下面找到代码的一些重要部分:
// Intermediate storage for the depth data received from the sensor
private DepthImagePixel[] depthPixels;
// Intermediate storage for the color data received from the camera
private byte[] colorPixels;
// Intermediate storage for the depth to color mapping
private ColorImagePoint[] colorCoordinates;
// Inverse scaling factor between color and depth
private int colorToDepthDivisor;
// Format we will use for the depth stream
private const DepthImageFormat DepthFormat = DepthImageFormat.Resolution320x240Fps30;
// Format we will use for the color stream
private const ColorImageFormat ColorFormat = ColorImageFormat.RgbResolution640x480Fps30;
//...
// Initialization
this.colorCoordinates = new ColorImagePoint[this.sensor.DepthStream.FramePixelDataLength];
this.depthWidth = this.sensor.DepthStream.FrameWidth;
this.depthHeight = this.sensor.DepthStream.FrameHeight;
int colorWidth = this.sensor.ColorStream.FrameWidth;
int colorHeight = this.sensor.ColorStream.FrameHeight;
this.colorToDepthDivisor = colorWidth / this.depthWidth;
this.sensor.AllFramesReady += this.SensorAllFramesReady;
//...
private void SensorAllFramesReady(object sender, AllFramesReadyEventArgs e)
{
// in the middle of shutting down, so nothing to do
if (null == this.sensor)
{
return;
}
bool depthReceived = false;
bool colorReceived = false;
using (DepthImageFrame depthFrame = e.OpenDepthImageFrame())
{
if (null != depthFrame)
{
// Copy the pixel data from the image to a temporary array
depthFrame.CopyDepthImagePixelDataTo(this.depthPixels);
depthReceived = true;
}
}
using (ColorImageFrame colorFrame = e.OpenColorImageFrame())
{
if (null != colorFrame)
{
// Copy the pixel data from the image to a temporary array
colorFrame.CopyPixelDataTo(this.colorPixels);
colorReceived = true;
}
}
if (true == depthReceived)
{
this.sensor.CoordinateMapper.MapDepthFrameToColorFrame(
DepthFormat,
this.depthPixels,
ColorFormat,
this.colorCoordinates);
// ...
int depthIndex = x + (y * this.depthWidth);
DepthImagePixel depthPixel = this.depthPixels[depthIndex];
// scale color coordinates to depth resolution
int X = colorImagePoint.X / this.colorToDepthDivisor;
int Y = colorImagePoint.Y / this.colorToDepthDivisor;
// depthPixel is the depth for the (X,Y) pixel in the color frame
}
}
答案 1 :(得分:1)
感谢Vito您的快速回复。我解决了Kinect sdk从深度框架到彩色框架提供给我。我从深度颜色映射的manuel逆事务中找到图像点(x,y)的深度值。
此功能返回特定彩色图像点的深度值。
public int GetDepthFromColorImagePoint(KinectSensor sensor, DepthImageFormat depthImageFormat, ColorImageFormat colorImageFormat, DepthImagePixel[] depthPixels, int depthWidth, int depthHeight, int colorImageX, int colorImageY)
{
ColorImagePoint[] color_points = new ColorImagePoint[depthHeight * depthWidth];
sensor.CoordinateMapper.MapDepthFrameToColorFrame(depthImageFormat, depthPixels, colorImageFormat, color_points);
int depthIndex = color_points.ToList().FindIndex(p => p.X == colorImageX && p.Y == colorImageY);
if (depthIndex < 0)
return -1;
short depthValue = depthPixels[depthIndex].Depth;
return depthValue;
}
如果您看到此功能的结果,请查看此gif