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). Since both elements are very similar it's easy to mix them up.
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.
In your code sample your 'CamImageBox' element is an ImageBox
. Adding a Bitmap
to an ImageBox
will indeed lead to the following error:
Cannot implicitly convert type 'System.Drawing.Bitmap' to
'Emgu.CV.IImage'
The great thing about the ImageBox
is that it provides you with additional features focused on EmguCV. One of these features is that you can directly show EmguCV Image<,>
and Mat
objects, which saves you a ToBitmap()
convert. If you want to keep using the ImageBox
element, either of the following two options are possible:
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. EmguCV 3.0 is
following along. Image<,> is not officially deprecated yet, but keep
this in mind.
Therefore, please beware that in EmguCV 3.0 QueryFrame()
will return a Mat
! See this answer for more information: 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.