[英]Display an EmguCV image in Windows Form Picture Box
Image<Bgr, Byte> ImageFrame = capture.QueryFrame(); //line 1
CamImageBox.Image = ImageFrame.ToBitmap();
I have used above code for Display
an EmguCV
image in Windows Form Picture Box, 我已使用以上代码在Windows Form Picture Box中
Display
EmguCV
图像,
But I have got an error: 但是我有一个错误:
cannot implicitly convert type 'system.drawing.bitmap' to 'emgu.cv.image'
无法将类型'system.drawing.bitmap'隐式转换为'emgu.cv.image'
This case also in Stackoverflow questions, but no one give proper answer for this. Stackoverflow问题中也有这种情况,但是没有人对此提供适当的答案。
You seem to mix up the PictureBox (provided by .NET framework in in System.Windows.Forms) and ImageBox (which is an EmguCV class in Emgu.CV.UI). 您似乎混淆了PictureBox (由System.Windows.Forms中的.NET框架提供)和ImageBox (这是Emgu.CV.UI中的EmguCV类)。 Since both elements are very similar it's easy to mix them up.
由于这两个元素非常相似,因此很容易将它们混合在一起。
ImageBox is a user control that is similar to PictureBox.
ImageBox是类似于PictureBox的用户控件。 Instead of displaying Bitmap, it display any Image<,> object.
它不显示位图,而是显示任何Image <,>对象。 It also provides extra functionality for simple image manipulation.
它还为简单的图像处理提供了额外的功能。
In your code sample your 'CamImageBox' element is an ImageBox
. 在您的代码示例你“CamImageBox”元素是
ImageBox
。 Adding a Bitmap
to an ImageBox
will indeed lead to the following error: 将
Bitmap
添加到ImageBox
确实会导致以下错误:
Cannot implicitly convert type 'System.Drawing.Bitmap' to 'Emgu.CV.IImage'
无法将类型'System.Drawing.Bitmap'隐式转换为'Emgu.CV.IImage'
The great thing about the ImageBox
is that it provides you with additional features focused on EmguCV. 关于伟大的事情
ImageBox
是,它为您提供了专注于EmguCV附加功能。 One of these features is that you can directly show EmguCV Image<,>
and Mat
objects, which saves you a ToBitmap()
convert. 这些功能之一是,您可以直接显示EmguCV
Image<,>
和Mat
对象,从而节省了ToBitmap()
转换。 If you want to keep using the ImageBox
element, either of the following two options are possible: 如果要继续使用
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*
Please note , 请注意 ,
as of
OpenCV 3.0
, IplImage is being phased out.从
OpenCV 3.0
,IplImage已被淘汰。 EmguCV 3.0 is following along.EmguCV 3.0随之而来。 Image<,> is not officially deprecated yet, but keep this in mind.
Image <,>尚未正式弃用,但请记住这一点。
Therefore, please beware that in EmguCV 3.0 QueryFrame()
will return a Mat
! 因此,请注意在EmguCV 3.0中
QueryFrame()
将返回Mat
! See this answer for more information: https://stackoverflow.com/a/19119408/7397065 请参阅此答案以获取更多信息: https : //stackoverflow.com/a/19119408/7397065
Also, your current code will work if you change the ImageBox
element to a PictureBox
element in your GUI. 另外,如果你改变你目前的代码将工作
ImageBox
元素的PictureBox
在GUI元素。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.