2012-04-30 185 views
8

我正在玩新的Kinect SDK v1.0.3.190。 (stackoverflow中的其他相關問題在kinect之前的sdk上) 我從Kinect獲得深度和顏色流。由於深度和RGB流通過不同的傳感器捕捉,所以兩個幀之間會有一個錯位,如下所示。Kinect深度和圖像幀對齊

只有RGB RGB

只有深度 Depth

深度& RGB RGB & Depth equally blended

我需要對準他們,有一個名爲MapDepthToColorImagePoint正是爲了這個目的功能。但它似乎並不奏效。這裏是一個同樣混合(深度和映射顏色)導致下面,其與下面的代碼

  Parallel.For(0, this.depthFrameData.Length, i => 
     { 
      int depthVal = this.depthFrameData[i] >> 3; 
      ColorImagePoint point = this.kinectSensor.MapDepthToColorImagePoint(DepthImageFormat.Resolution640x480Fps30, i/640, i % 640, (short)depthVal, ColorImageFormat.RgbResolution640x480Fps30); 
      int baseIndex = Math.Max(0, Math.Min(this.videoBitmapData.Length - 4, (point.Y * 640 + point.X) * 4)); 

      this.mappedBitmapData[baseIndex] = (byte)((this.videoBitmapData[baseIndex])); 
      this.mappedBitmapData[baseIndex + 1] = (byte)((this.videoBitmapData[baseIndex + 1])); 
      this.mappedBitmapData[baseIndex + 2] = (byte)((this.videoBitmapData[baseIndex + 2])); 
     }); 

其中

depthFrameData -> raw depth data (short array) 

videoBitmapData -> raw image data (byte array) 

mappedBitmapData -> expected result data (byte array) 

順序的參數,分辨率,陣列尺寸是正確的創建(雙重檢查) 。

代碼的結果是: depth and MapDepthToColorImagePoint

失準繼續!更糟糕的是,使用MapDepthToColorImagePoint後的結果圖像與原始圖像完全相同。

,將不勝感激,如果有人可以幫助我找到了我的錯誤,或者至少給我解釋一下什麼是(假設我誤解了它的功能)MapDepthToColorImagePoint?

回答

1

這是一個非常普遍的問題,涉及到同步的兩個圖像,因爲這兩個相機都坐在兩個不同的地方數學內在的東西。有點像採用由3D相機產生的兩個視頻源並嘗試同步它們。他們會一直稍微偏離。

整改

兩個想法:

  1. 手動爲你計算出它的位從深度偏移圖像。
  2. 振動器電機添加到Kinect的減少噪音: http://www.youtube.com/watch?v=CSBDY0RuhS4(我找到了一個簡單的振動電機是有效的。)

的MapDepthToColorImagePoint是骨骼肌API在使用骨骼點映射到深度點,然後到圖像點,以便您可以在RGB圖像頂部顯示關節。

希望這會有所幫助。

4

,因爲兩個傳感器安裝在稍有不同的地方這將始終略微發生。

試試:

看一些對象與你的兩隻眼睛,然後嘗試只用你的左眼,那麼只有你的右眼。事情看起來有些不同,因爲你的兩隻眼睛不在完全相同的地方。

但是:有些API代碼可以解決很多問題。

我使用Kinect for Windows 1.5,因此API與1.0稍有不同。

short[] depth=new short[320*240]; 
// fill depth with the kinect data 
ColorImagePoint[] colorPoints=new ColorImagePoint[320*240]; 
// convert mappings 
kinect.MapDepthFrameToColorFrame(DepthImageFormat.Resolution320x240Fps30, 
      depth, ColorImageFormat.RgbResolution640x480Fps30, colorPoints); 
// now do something with it 
for(int i=0;i<320*240;i++) 
{ 
    if (we_want_to_display(depth[i])) 
    { 
    draw_on_image_at(colorPoints[i].X,colorPoints[i].Y); 
    } 
} 

這就是基礎知識。 如果您查看Kinect Developer Toolkit 1.5中的綠屏示例,它將非常有用。