Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert Bitmap to Image<Bgr, Byte>

Tags:

c#

.net

opencv

I am using the OpenCV library for image processing.

I want to convert a System.Drawing.Bitmap to an Image<Bgr, Byte>. How can I do this?

like image 386
Lemmouchi Rédha Dida Avatar asked Apr 26 '13 16:04

Lemmouchi Rédha Dida


4 Answers

The Image constructor has a Bitmap overload (assuming you're using the Emgu CV wrapper since you've marked it .NET).

Image<Bgr, Byte> myImage = new Image<Bgr, Byte>(myBitmap); 
like image 194
keyboardP Avatar answered Nov 12 '22 03:11

keyboardP


In .NET Emgu.CV 4.4.0.4099 I had to install Emgu.CV.Bitmap 4.4.0.4099 and Emgu.CV.runtime.windows in order to use the bitmap.ToImage<Bgr, byte>() extension method.

like image 14
Nikolay Kostov Avatar answered Nov 12 '22 01:11

Nikolay Kostov


The constructor for Image<Bgr, byte> no longer accepts Bitmap as parameter. I had to use the following code for Emgu version 4.3:

Image<Bgr, byte> emguImage = bitmap.ToImage<Bgr, byte>();

I found it on github and in patch notes. The official documentation tutorials were not properly updated.

like image 14
miran80 Avatar answered Nov 12 '22 03:11

miran80


I am using Emgu.CV 4.5.1.4349 on NetStandard 2.1 Need to install Emgu.CV.Bitmap and Emgu.CV.runtime.windows in order to convert your Bitmap to Image<Bgr, byte>

var myImage = myBitmap.ToImage<Bgr, byte>()

like image 3
christopher Ng Avatar answered Nov 12 '22 01:11

christopher Ng