11

I am new to EmguCV. I want to convert an rgb image into gray scale. For the conversion I have used the code

Image<Gray,byte> grayImage = ColordImage.Convert<Gray, byte>();

Now when i compile this code in C# it gives no error,but when i run it then after a few seconds it gives me the exception at this line of code that this type of conversion is not supported by OpenCV. Now can any one help me solve this problem.

Regards Amal

Amal
  • 1,395
  • 3
  • 9
  • 9
  • 1
    Tom Wright's answer worked for me. If it worked for you, please accept the answer. – Chad Sep 30 '16 at 15:53

4 Answers4

15

It may depend on the type of colour that ColordImage is.

For instance, this works:

Capture cap = new Capture(1);
Image <Bgr,Byte> ColordImage = cap.QueryFrame();
Image <Gray,Byte> grayImage = ColordImage.Convert<Gray, Byte>();
imageBox1.Image = grayImage;

If you could supply more of your code, it might become more obvious what's going on.

Tom Wright
  • 11,278
  • 15
  • 74
  • 148
5

You should paste opencv_imgproc220.dll(if you use emgu cv 2.2.1.1150) to your project bin/debug folder.

Abu Yousuf
  • 5,729
  • 3
  • 31
  • 50
  • 2
    This answer looks stupid but its the correct answer. I checked ColordImage.Convert() in ILSpy, the function uses Image.ConvertColor() which contains try/catch block that catches everything, including dll load errors. – Markos Nov 09 '12 at 20:19
5

Alternately, if you don't want to use Convert (e.g. in case your ColoredImage is some other data type such as IntPtr), there are numerous constructors available such as:

Image<Gray, byte> grayFrame = new Image<Gray, byte>(width, height, stride, imageData);

Here is a full list:
http://www.emgu.com/wiki/files/2.1.0.0/html/cb45d54d-ebce-44b6-0352-3e1105c0862a.htm

There are also some more examples (including usage of Convert) on the emgu Wiki: http://www.emgu.com/wiki/index.php/Working_with_Images

glenneroo
  • 1,908
  • 5
  • 30
  • 49
4

One simple way is to pass BitMap of color image in the constructor;

Image<Bgr, byte> inputImage = //your original bgr image
Image<Gray, Byte> result = new Image<Gray,byte>(inputImage.Bitmap);
vincent mathew
  • 4,278
  • 3
  • 27
  • 34