Conversion to grayscale using emguCV in C#

Amal picture Amal · Jun 1, 2010 · Viewed 36.4k times · Source

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

Answer

Tom Wright picture Tom Wright · Jun 28, 2010

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.