Michael
Michael

Reputation: 13616

How to convert Image type to Image<Bgr, Byte>?

Any Idea how to convert Image type to Image<Bgr, Byte> type?

I get the image from PictureBox Control and I need to convert it to Image<Bgr, Byte> type.

Image pictureBoxImage = pictureBox.Image;
Image<Bgr, Byte> image = // ...

Upvotes: 2

Views: 18223

Answers (3)

IAmCoder
IAmCoder

Reputation: 3442

For Emgu.CV 4.5 I had to add the Emgu.CV.Bitmap package and use bitmap.ToImage<Bgr, byte>():

using (Bitmap bitmap = new Bitmap(pictureBox.Image))
{
    Image<Bgr, byte> image = bitmap.ToImage<Bgr, byte>();
}

Upvotes: 1

Hermes1312
Hermes1312

Reputation: 33

You can also do it like this:

Image<Bgr, Byte> IMG = new Image<Bgr, byte>((Bitmap)pictureBox1.Image);

OR

var IMG = new Image<Bgr, byte>((Bitmap)pictureBox1.Image);

Upvotes: 1

Paolo Moretti
Paolo Moretti

Reputation: 55956

According the documentation:

Creating image from Bitmap

It is also possible to create an Image<TColor, TDepth> from a .Net Bitmap object

So, you should be able to do:

var image = new Image<Bgr, Byte>(new Bitmap(pictureBox.Image));

Upvotes: 5

Related Questions