1
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,

But I have got an error:

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

This case also in Stackoverflow questions, but no one give proper answer for this.

VMAtm
  • 27,943
  • 17
  • 79
  • 125
gihansalith
  • 1,770
  • 5
  • 17
  • 21
  • 2
    I guess capture.QueryFrame() is a System.Drawing.Bitmap. You should try to load it like this: Image ImageFrame =new Image(capture.QueryFrame()); – David_D May 05 '15 at 09:43

1 Answers1

0

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.

Community
  • 1
  • 1
Jurjen
  • 1,376
  • 12
  • 19