11

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

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

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

问候阿马尔

4

4 回答 4

15

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

例如,这有效:

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

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

于 2010-06-28T12:26:17.007 回答
5

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

Image<Gray, byte> grayFrame = new Image<Gray, byte>(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

于 2010-12-12T17:02:12.697 回答
5

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

于 2012-08-03T22:23:25.400 回答
4

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

Image<Bgr, byte> inputImage = //your original bgr image
Image<Gray, Byte> result = new Image<Gray,byte>(inputImage.Bitmap);
于 2014-09-02T18:32:52.530 回答