2013-02-25 76 views
0

我在Kinect的編程新手,我是在一個球的加工利用Kinect的跟蹤和opencv..we都知道Kinect的提供深度數據,並與下面的代碼:獲取其他對象的深度的Kinect

DepthImagePoint righthandDepthPoint = 
    sensor.CoordinateMapper.MapSkeletonPointToDepthPoint 
    (
     me.Joints[JointType.HandRight].Position, 
     DepthImageFormat.Resolution640x480Fps30 
    ); 

double rightdepthmeters = (righthandDepthPoint.Depth); 
使用這種

,我能得到一個右手的深度,通過specifing的jointtype使用功能MapSkeletonPointToDepthPoint() ..

是否有可能像凡在指定讓其他對象的深度? 給定的座標..我想獲得在該座標中的對象的深度?

回答

0

從Kinect SDK中提取深度數據可以從DepthImagePixel結構中提取。

下面的示例代碼循環遍歷整個DepthImageFrame來檢查每個像素。如果您希望查看特定座標,請刪除for循環,並將xy設置爲特定值。

// global variables 

private const DepthImageFormat DepthFormat = DepthImageFormat.Resolution320x240Fps30; 
private const ColorImageFormat ColorFormat = ColorImageFormat.RgbResolution640x480Fps30; 

private DepthImagePixel[] depthPixels; 

// defined in an initialization function 

this.depthWidth = this.sensor.DepthStream.FrameWidth; 
this.depthHeight = this.sensor.DepthStream.FrameHeight; 

this.depthPixels = new DepthImagePixel[this.sensor.DepthStream.FramePixelDataLength]; 

private void SensorAllFramesReady(object sender, AllFramesReadyEventArgs e) 
{ 
    if (null == this.sensor) 
     return; 

    bool depthReceived = 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; 
     } 
    } 

    if (true == depthReceived) 
    { 
     // loop over each row and column of the depth 
     for (int y = 0; y < this.depthHeight; ++y) 
     { 
      for (int x = 0; x < this.depthWidth; ++x) 
      { 
       // calculate index into depth array 
       int depthIndex = x + (y * this.depthWidth); 

       // extract the given index 
       DepthImagePixel depthPixel = this.depthPixels[depthIndex]; 

       Debug.WriteLine("Depth at [" + x + ", " + y + "] is: " + depthPixel.Depth); 
      } 
     } 
    } 
} 
+0

非常感謝您的先生! :D這正是我所需要的。 – muffin 2013-02-26 04:20:25

+0

先生,我有另一個問題..深度像素。深度打算返回深度的毫米單位或應該我仍然需要一些轉換嗎? ..這個代碼很好..但是,返回的深度不同於骨骼關節的長度在幾米..我看到巨大的數字,雖然我的對象是如此接近,我做錯了什麼,或者這個代碼應該完美嗎? – muffin 2013-02-26 05:21:23

+0

值應以毫米爲單位。 http://msdn.microsoft.com/en-us/library/microsoft.kinect.depthimagepixel_members.aspx – 2013-02-26 14:17:51