【问题标题】:How to show Kinect depth data in millimeters如何以毫米为单位显示 Kinect 深度数据
【发布时间】:2013-09-16 21:31:11
【问题描述】:

我正在创建一个程序,它可以从 Kinect 截取两张截图(一张 IR 图像和一张深度图像),将其直接加载到两个图片框中,然后通过单击测量 IR 截图中点的位置鼠标。

在 IR 屏幕截图中获取 x- 和 y- 位置没有问题,我需要的也是以 mm 为单位的深度 - 考虑到 IR 和深度图像是从同一个相机拍摄的,所以当我点击鼠标它应该将 x- 和 y- 坐标链接到深度图像以获取以 mm 为单位的深度值。

我的想法是在 SensorDepthFrameReady 方法中访问变量 short depth = depthPixels[i].Depth;。但为什么它不起作用?为什么深度图像显示为灰度而不是 RGB(与 Kinect Studio 不同)?

private void SensorDepthFrameReady(object sender, DepthImageFrameReadyEventArgs e)
{
 using (DepthImageFrame depthFrame = e.OpenDepthImageFrame())
 {
  if (depthFrame != null)
  {
  depthFrame.CopyDepthImagePixelDataTo(this.depthPixels);
  int colorPixelDDIndex = 0;
  for (int i = 0; i < this.depthPixels.Length; ++i)
  {
   short depth = depthPixels[i].Depth;
   ...
  }
  this.colorBitmapDD.WritePixels(new Int32Rect(0, 0, this.colorBitmapDD.PixelWidth, this.colorBitmapDD.PixelHeight),this.colorPixelsDD,this.colorBitmapDD.PixelWidth * sizeof(int),0);
  }
 }
}

private void imageIR_MouseClick(object sender, System.Windows.Input.MouseEventArgs e)
{
 System.Windows.Point mousePoint = e.GetPosition(imageIR);
 double xpos_IR = mousePoint.X;
 double ypos_IR = mousePoint.Y;
 lbCoord.Content = "x- & y- Koordinate [pixel]: " + xpos_IR + " ; " + ypos_IR;
 zpos.Content = "z- Koordinate [mm]: " + depth;
}

有解决问题的办法吗?提前致谢。

主程序截图:

http://i.stack.imgur.com/bljQ9.jpg

【问题讨论】:

  • 你在哪里设置你的imageIR_MouseClick-handler 中使用的depth 变量?
  • zpos.Content = "z- 坐标 [mm]:" + 深度; -> 即使我将方法更改为 public void,直接访问局部变量仍然不起作用。
  • 一种选择是将每个深度值与它的 x 和 y 值一起保存在全局变量中。也许是Dictionary&lt;Point,short&gt;。而不是在您的MouseClick-handler 中阅读它:zpos.Content = "z- Koordinate [mm]: " + _depthDic[new Point(xpos_IR,ypos_IR)];
  • 很抱歉问了一些愚蠢的问题,但我对编程很陌生。所以 Point 包含 2 个值:xpos_IR 和 ypos_IR,我如何在全局变量中声明它?类似于:Private Dictionary depthDic ?
  • 看看我的回答 ;)

标签: c# wpf kinect depth


【解决方案1】:

一种选择是将每个深度值及其 x 和 y 值保存在全局变量中。也许是Dictionary&lt;Point,short&gt;。而不是在你的鼠标点击处理程序中阅读它:zpos.Content = "z- Koordinate [mm]: " + _depthDic[new Point(xpos_IR,ypos_IR)];

你通过private Dictionary&lt;Point,short&gt; _depthDic = new Dictionary&lt;Point,short&gt;();声明你的全局变量

并将其设置在您的 SensorDepthFrameReady 处理程序中:

for (int i = 0; i < this.depthPixels.Length; ++i)
{
   Point coords = new Point(depthPixels[i].X, depthPixels[i].Y);
   _depthDic[coords] = depthPixels[i].Depth;
 ...
}

编辑:另一种方法。创建一个包含当前DepthImageFrame 的全局字段。将此DepthImageFrame 保存在您的 SensorDepthFrameReady 方法中:

private DepthImageFrame _depthImageFrame;
private bool _imageUsing;
private void SensorDepthFrameReady(object sender, DepthImageFrameReadyEventArgs e)
{
 using (DepthImageFrame depthFrame = e.OpenDepthImageFrame())
 {
  if (depthFrame != null)
  {
      if (!_imageUsing)
          _depthImageFrame = depthFrame;

      //your code
  }
 }
}

然后创建一个将深度值返回到特定 x 和 y 值的方法:

private int GetDepthValue(DepthImageFrame imageFrame, int x, int y)
{
   _imageUsing = true;
   short[] pixelData = new short[imageFrame.PixelDataLength];
   imageFrame.CopyPixelDataTo(pixelData);
   var result = ((ushort)pixelData[x + y * imageFrame.Width])>>3 ;
   _imageUsing = false;
   return result;
}

最后显示鼠标点击的值:

private void imageIR_MouseClick(object sender, System.Windows.Input.MouseEventArgs e)
{
 System.Windows.Point mousePoint = e.GetPosition(imageIR);
 double xpos_IR = mousePoint.X;
 double ypos_IR = mousePoint.Y;
 lbCoord.Content = "x- & y- Koordinate [pixel]: " + xpos_IR + " ; " + ypos_IR;
 if (_depthImageFrame != null)
     zpos.Content = "z- Koordinate [mm]: " + GetDepthValue(_depthImageFrame, Convert.toInt16(mousePoint.X),Convert.toInt16(mousePoint.Y));
}

也许这可以帮助你:http://www.i-programmer.info/ebooks/practical-windows-kinect-in-c/3802-using-the-kinect-depth-sensor.html

【讨论】:

  • 显示错误:“Microsoft.Kinect.DepthImagePixel”不包含“Y”的定义,并且没有扩展方法“Y”接受“Microsoft.Kinect.DepthImagePixel”类型的第一个参数被发现(您是否缺少 using 指令或程序集引用?)
  • 由于我不使用 kinect 编程,我不知道哪些属性存在或不存在。显然 DepthImagePixel 类没有 X 和 Y 属性。所以你必须自己想办法得到DepthPixel的X和Y坐标,但其余的应该都可以。
  • 是的,但它与红外图像具有相同的高度和宽度,因为它是从同一相机拍摄的。那么如何将红外图像中的 x 和 y 坐标转换为深度图像呢?在 Kinect Studio 中,它看起来像这样:m84i.img-up.net/Unbenanntf5ba.png?l=de
  • 或者是否可以在 imageIR_MouseClick 方法中访问 double xpos_IR = mousePoint.X;double ypos_IR = mousePoint.Y; ?因为如果可能的话,我只需将 depthPixels[i].X 声明为 mousePoint.X 对吗?
  • 不,因为 SensorDepthFrameReady 方法中没有 mousePoint。看看我的编辑;)
猜你喜欢
  • 2012-02-08
  • 1970-01-01
  • 1970-01-01
  • 2014-07-17
  • 1970-01-01
  • 2012-05-08
  • 2016-05-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多