【发布时间】: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;
}
有解决问题的办法吗?提前致谢。
主程序截图:
【问题讨论】:
-
你在哪里设置你的
imageIR_MouseClick-handler 中使用的depth变量? -
zpos.Content = "z- 坐标 [mm]:" + 深度; -> 即使我将方法更改为 public void,直接访问局部变量仍然不起作用。
-
一种选择是将每个深度值与它的 x 和 y 值一起保存在全局变量中。也许是
Dictionary<Point,short>。而不是在您的MouseClick-handler 中阅读它:zpos.Content = "z- Koordinate [mm]: " + _depthDic[new Point(xpos_IR,ypos_IR)]; -
很抱歉问了一些愚蠢的问题,但我对编程很陌生。所以 Point 包含 2 个值:xpos_IR 和 ypos_IR,我如何在全局变量中声明它?类似于:Private Dictionary
depthDic ? -
看看我的回答 ;)