在C#中使用emguCV转换为灰度

我是EmguCV的新手。 我想将rgb图像转换为灰度图像。 对于转换,我使用了代码

Image grayImage = ColordImage.Convert(); 

现在,当我在C#中编译此代码时,它没有给出任何错误,但是当我运行它时,几秒钟之后,它在这行代码中给出了exception,OpenCV不支持这种类型的转换。 现在任何人都可以帮我解决这个问题。

关心Amal

它可能取决于ColordImage的颜色类型。

例如,这有效:

 Capture cap = new Capture(1); Image  ColordImage = cap.QueryFrame(); Image  grayImage = ColordImage.Convert(); imageBox1.Image = grayImage; 

如果您可以提供更多代码,那么发生的事情可能会变得更加明显。

或者,如果您不想使用Convert (例如,如果您的ColoredImage是其他数据类型,如IntPtr),则有许多可用的构造函数,例如:

 Image grayFrame = new Image(width, height, stride, imageData); 

这是一个完整的清单:
http://www.emgu.com/wiki/files/2.1.0.0/html/cb45d54d-ebce-44b6-0352-3e1105c0862a.htm

在emgu Wiki上还有一些更多的例子(包括Convert的用法): http ://www.emgu.com/wiki/index.php/Working_with_Images

您应该将opencv_imgproc220.dll(如果使用emgu cv 2.2.1.1150)粘贴到项目bin / debug文件夹中。

一种简单的方法是在构造函数中传递彩色图像的BitMap;

 Image inputImage = //your original bgr image Image result = new Image(inputImage.Bitmap);