2015-05-04 91 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元素。