0

Kinect から 2 つのスクリーンショット (1 つの IR イメージと 1 つの深度イメージ) を取得し、それを 2 つの画像ボックスに直接ロードし、マウスをクリックして IR スクリーンショットのポイントの位置を測定できるプログラムを作成しています。

IR スクリーンショットで x- と y- の位置を取得するのに問題はありません。必要なのは深さ (mm) です - IR と深さの画像が同じカメラから取得されたことを考えると、マウスをクリックするとx 座標と y 座標を深度画像にリンクして、深度値を mm 単位で取得する必要があります。

私の考えは、変数short depth = depthPixels[i].Depth;にアクセスすることでした。メソッドSensorDepthFrameReadyで。しかし、なぜうまくいかなかったのでしょうか。深度画像が 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

4

1 に答える 1

0

1 つのオプションは、各深度値をその x 値と y 値と共にグローバル変数に保存することです。たぶんDictionary<Point,short>。そして、あなたの MouseClick-handler でそれを読んでください:zpos.Content = "z- Koordinate [mm]: " + _depthDic[new Point(xpos_IR,ypos_IR)];

グローバル変数を宣言しますprivate Dictionary<Point,short> _depthDic = new Dictionary<Point,short>();

SensorDepthFrameReady-handler に設定します。

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

編集:別のアプローチ。現在の を保持するグローバル フィールドを作成しますDepthImageFrameDepthImageFrameこれを 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

于 2013-09-12T14:06:57.110 に答える