您似乎混淆了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
。添加Bitmap
到ImageBox
确实会导致以下错误:
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
元素。
我猜capture.QueryFrame()是一个System.Drawing.Bitmap。您应该尝试像这样加载它:Image ImageFrame = new Image (capture.QueryFrame()); –