2013-08-05 65 views
1

我剛開始使用EmguCV爲Kinect的圖像處理,並且從深度流這樣創建EmguCV圖像時一個ArgumentException發生:轉換Kinect的深度圖像EmguCV圖像誤差

private void DepthFrameReady(object sender, DepthImageFrameReadyEventArgs e) 
    { 
     DepthImageFrame df = e.OpenDepthImageFrame(); 
     if (df != null) 
     { 
      short[] data = new short[df.PixelDataLength]; 
      df.CopyPixelDataTo(data); 
      Bitmap b = data.ToBitMap(df.Width, df.Height, System.Drawing.Imaging.PixelFormat.Format16bppGrayScale); 
      Image<Gray, short> im = new Image<Gray, short>(b); //run-time exception here 

的ToBitmap擴展方法被完全複製從Kinect的SDK教程例如:

public static Bitmap ToBitmap(this short[] data, int width, int height, System.Drawing.Imaging.PixelFormat format) 
    { 
     var bitmap = new Bitmap(width, height, format); 

     var bitmapData = bitmap.LockBits(
      new System.Drawing.Rectangle(0, 0, bitmap.Width, 
      bitmap.Height), 
      ImageLockMode.WriteOnly, 
      bitmap.PixelFormat); 
     Marshal.Copy(data, 0, bitmapData.Scan0, data.Length); 
     bitmap.UnlockBits(bitmapData); 
     return bitmap; 
    } 

我檢查了b有一個有效的價值,而不是空。我想知道爲什麼會發生這種異常,它是一些圖像格式問題?

回答

0

嘗試使用:

Image<Gray, byte> im = new Image<Gray, byte>(b); 
+0

我已經發現'B'是無效的,當我改變位圖的格式RGB565它的工作,用''一起。但是如果我需要保持16位精度,我應該怎麼做?我聽說'bitmap'並沒有真正支持16bit灰度,因爲沒有16bit顯卡,這是真的嗎?現在我試着用''作爲中等格式,然後再將數據複製到'short []',然後直接將'short []'轉換爲'BitmapSource',我會測試它是否有效。非常感謝 – Cherry