2015-02-09 150 views
1

我使用官方的Kinect SDK 2.0和Emgu CV來識別Rubik's Cube的顏色。Kinect v2紅外傳感器和RGB圖像的對齊總是稍微偏離

enter image description here

起初我用Canny邊緣提取物對紅外攝像機,因爲它處理比RGB攝像頭更好的不同照明條件和要好得多檢測輪廓。

然後,我使用此代碼將紅外傳感器的座標轉換爲RGB相機的座標。 正如你可以看到圖片中他們仍然不符合我的要求。由於我已經使用官方KinectSensor.CoordinateMapper.MapDepthFrameToColorSpace,我不知道如何改善這種情況。

using (var colorFrame = reference.ColorFrameReference.AcquireFrame()) 
using (var irFrame = reference.InfraredFrameReference.AcquireFrame()) 
{ 
    if (colorFrame == null || irFrame == null) 
     return; 

    // initialize depth frame data 
    FrameDescription depthDesc = irFrame.FrameDescription; 

    if (_depthData == null) 
    { 
     uint depthSize = depthDesc.LengthInPixels; 
     _depthData = new ushort[depthSize]; 
     _colorSpacePoints = new ColorSpacePoint[depthSize]; 

     // fill Array with max value so all pixels can be mapped 
     for (int i = 0; i < _depthData.Length; i++) 
     { 
      _depthData[i] = UInt16.MaxValue; 
     } 
     // didn't work so well with the actual depth-data 
     //depthFrame.CopyFrameDataToArray(_depthData); 

     _sensor.CoordinateMapper.MapDepthFrameToColorSpace(_depthData, _colorSpacePoints); 
    } 
} 

這是一個輔助功能我爲了點陣列轉換紅外空格鍵以色彩空間

public static System.Drawing.Point[] DepthPointsToColorSpace(System.Drawing.Point[] depthPoints, ColorSpacePoint[] colorSpace){ 
     for (int i = 0; i < depthPoints.Length; i++) 
     { 
      // 512 is the width of the depth/infrared image 
      int index = 512 * depthPoints[i].Y + depthPoints[i].X; 

      depthPoints[i].X = (int)Math.Floor(colorSpace[index].X + 0.5); 
      depthPoints[i].Y = (int)Math.Floor(colorSpace[index].Y + 0.5); 
     } 
     return depthPoints; 
    } 
+0

都是真的一樣嗎?在紅外傳感器中,我們可以看到左側仍然有很多空間,而您是RGB圖像中的左側邊緣 – chouaib 2015-02-09 00:55:25

+1

不,它們不一樣。一個來自RGB攝像機(1920 x 1080),另一個來自紅外傳感器(512 x 424)。對於Kinect v2,它們具有不同的分辨率和視角。這就是爲什麼我必須使用Kinect v2 SDK中的'CoordinateMapper'。 – Hedge 2015-02-09 01:10:15

+0

我對Kinect並不熟悉,但是您可能會錯過一些抵消! – chouaib 2015-02-09 01:12:19

回答

0

它的創建,因爲它不一樣的攝像頭,檢索深度相機數據和檢索顏色數據的數據。 因此,您應該應用校正因子來替換深度數據。 它是一個幾乎不變的因素,但它與距離有關。 我沒有代碼給你,但它可以計算自己的東西。