I was new to Emgu Cv and i was wondering if someone could let me know how i change Emgu.Cv.Image to System.Image?If there is a need for further explanation, let me know and i will do it.The language i am using is C#.
Asked
Active
Viewed 1.6k times
2 Answers
5
You can just use the ToImage()
method to get a System.Drawing.Bitmap
(which is a derived class of System.Drawing.Image
), so something like this
// create an Emgu image of 400x200 filled with Blue color
Image<Bgr, Byte> img = new Image<Bgr, byte>(400, 200, new Bgr(255, 0, 0));
// copy to a .NET image
System.Drawing.Image pMyImage = img.ToBitmap();
Is that what you mean?

Roger Rowland
- 25,885
- 11
- 72
- 113
-
I was working on a Face Recognition application.The problem is, i got a black image with unrecognized label when i use EigenObjectRecognizer.I was wondering if this problem emanates from the fact that i was converting Emgu.CV.Image
to Bitmap using img.ToBitmap() and display it in a box may be i am losing data on the pixel or something.Is that why i am getting a black image?May be if there is a better way.I dont know.The thread is here[code](http://stackoverflow.com/questions/16512362/face-recognition-code-using-emgu-cv-and-c-sharp-and-it-returns-a-black-image-and) – Sisay May 19 '13 at 19:47 -
This does not work in Emgu.CV 4.5.5 at least. There is no Image.ToBitmap() method. – CodeOrElse Sep 25 '22 at 23:01
0
The accepted answer is outdated as newer versions of Emgu CV have been released where the Image<Bgr, byte>
object does not have a ToBitmap()
method. To convert an instance of Image<Bgr, byte>
to Bitmap
object then you need to get a byte array from the image and then use the byte array to build a memory stream object then pass the memory stream object to the Bitmap constructor overload that takes a Memory Stream object parameter.
//load an image into an Image<Byte, byte> object
var image = new Image<Bgr, byte>("file.png");
//get the jpeg representation of the image
var arr = image.ToJpegData(95);
//get a memory stream out of the byte array
var stream = new MemoryStream(arr) ;
//pass the memory stream to the bitmap ctor
var bitmap = new Bitmap(stream) ;
//TO DO with bitmap

Son of Man
- 1,213
- 2
- 7
- 27