how to convert mat to image
Asked Answered
K

3

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?

Kavanaugh answered 21/1, 2016 at 2:34 Comment(2)
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<Bgr, Byte> img = mat.ToImage<Bgr, Byte>();? Its not tested but should work.Ellissa
@Ellissa 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.Kavanaugh
K
17

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

 Image<Bgr, Byte> imgeOrigenal = capWebcam.QueryFrame().ToImage<Bgr, Byte>();
Kavanaugh answered 21/1, 2016 at 12:13 Comment(0)
T
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);
Tegucigalpa answered 8/1, 2019 at 13:0 Comment(0)
C
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>();
Curriery answered 18/1, 2023 at 14:3 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.