2015-05-04 82 views
1
Image<Bgr, Byte> ImageFrame = capture.QueryFrame(); //line 1 
CamImageBox.Image = ImageFrame.ToBitmap(); 

我上面的Display在Windows窗體圖片框中的EmguCV圖像的代碼中使用,顯示在Windows窗體圖片框中的EmguCV圖像

但我得到了一個錯誤:

cannot implicitly convert type 'system.drawing.bitmap' to 'emgu.cv.image'

這情況也在Stackoverflow的問題,但沒有人給出適當的答案。

+2

我猜capture.QueryFrame()是一個System.Drawing.Bitmap。您應該嘗試像這樣加載它:Image ImageFrame = new Image (capture.QueryFrame()); –

回答

1

您似乎混淆了PictureBox(由System.Windows.Forms中的.NET框架提供)和ImageBox(它是Emgu.CV.UI中的EmguCV類提供)。由於這兩個元素非常相似,所以很容易將它們混合起來。

ImageBox is a user control that is similar to PictureBox. Instead of displaying Bitmap, it display any Image<,> object. It also provides extra functionality for simple image manipulation.

在您的代碼示例中,您的'CamImageBox'元素是ImageBox。添加BitmapImageBox確實會導致以下錯誤:

Cannot implicitly convert type 'System.Drawing.Bitmap' to 'Emgu.CV.IImage'

的偉大的事情有關ImageBox的是,它爲您提供了專注於EmguCV附加功能。其中一個功能是您可以直接顯示EmguCV Image<,>Mat對象,這可以爲您節省一個ToBitmap()轉換。如果你想使用ImageBox元素保留,無論是以下兩個選項是可能的:

Mat matImage = capture.QueryFrame(); 
CamImageBox.Image = matImage; // Directly show Mat object in *ImageBox* 
Image<Bgr, byte> iplImage = matImage.ToImage<Bgr, byte>(); 
CamImageBox.Image = iplImage; // Show Image<,> object in *ImageBox* 

請注意

as of OpenCV 3.0 , IplImage is being phased out. EmguCV 3.0 is following along. Image<,> is not officially deprecated yet, but keep this in mind.

因此,請當心,在EmguCV 3.0 QueryFrame()將返回Mat!看到這個答案的詳細資料:https://stackoverflow.com/a/19119408/7397065

而且,當前的代碼將工作如果你ImageBox元素更改爲您的GUI一個PictureBox元素。