8

I need to convert a Mat to an Image in Emgu CV. Trying to cast a Mat to an image produces an exception: Cannot implicitly convert type 'Emgu.CV.Mat' to 'Emgu.CV.Image

Image<Bgr, Byte> imgeOrigenal;

Capture capWebcam = null;

imgeOrigenal = capWebcam.QueryFrame();//error line

How can I convert the Mat to an Image?

Bassie
  • 9,529
  • 8
  • 68
  • 159
Ehsan Jeihani
  • 1,238
  • 2
  • 14
  • 23
  • 4
    It is nice to know that you need testet AND working code. Please remember that stackoverflow isn't a code generator. What have you tried so far to convert your Mat? Have you tried the following: *Image img = mat.ToImage();*? Its not tested but should work. – David_D Jan 21 '16 at 09:16
  • @David_D what you have done so far is what exactly i mean. this question is asked many times but not answer correctly as you did. thank you. – Ehsan Jeihani Jan 21 '16 at 12:04

3 Answers3

17

the correct answer is the first comment @David_D sent under the question.

 Image<Bgr, Byte> imgeOrigenal = capWebcam.QueryFrame().ToImage<Bgr, Byte>();
Ehsan Jeihani
  • 1,238
  • 2
  • 14
  • 23
0

In can you want to show the image in a pictureBox or a dataGridView, you can also load the image as a Bitmap object like this:

imgeOrigenal = new Bitmap(capWebcam.Bitmap);
Ali Tourani
  • 1,170
  • 3
  • 21
  • 31
0

I do it like this (and seems to work fine for all my purposes):

//BGR
Image<Bgr, byte> grayframe = yourMat.Clone().ToImage<Bgr, byte>();

//GRAYSCALE
Image<Gray, byte> grayframe = yourMat.Clone().ToImage<Gray, byte>();
A. Dzebo
  • 558
  • 6
  • 13