Question

I have problem in converting System.Drawing.Image to Emgu.CV.Image. i can load my image in formapplication

string im_name = str[index];
Emgu.CV.Image<Bgr, Byte> img = new Image<Bgr, byte>(im_name);

but this code gives me error of invalid arguments

System.Drawing.Image img_btmap = System.Drawing.Image.FromFile( im_name);

Emgu.CV.Image<Bgr, Byte> img1 = new Image<Bgr, byte>(img_btmap);

Somebody has idea why??? regards

Was it helpful?

Solution

Change the line to:

System.Drawing.Bitmap img_btmap = new System.Drawing.Bitmap(im_name);

The Emgu.CV.Image constructor is expecting Bitmap class which inherits from Image class.

Make sure to dispose img_btmap later otherwise you risk the file being locked.

Edit: most simple way of ensuring proper disposing is using the using block like this:

using (System.Drawing.Bitmap img_btmap = new System.Drawing.Bitmap(im_name))
{
   //.....rest of code comes here.....
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top