[英]Conversion to grayscale using emguCV in C#
我是EmguCV的新手。 我想将rgb图像转换为灰度图像。 对于转换,我使用了代码
Image<Gray,byte> grayImage = ColordImage.Convert<Gray, byte>();
现在,当我在C#中编译此代码时,它没有给出任何错误,但是当我运行它时,几秒钟之后,它在这行代码中给出了异常,OpenCV不支持这种类型的转换。 现在任何人都可以帮我解决这个问题。
关心Amal
它可能取决于ColordImage的颜色类型。
例如,这有效:
Capture cap = new Capture(1);
Image <Bgr,Byte> ColordImage = cap.QueryFrame();
Image <Gray,Byte> grayImage = ColordImage.Convert<Gray, Byte>();
imageBox1.Image = grayImage;
如果您可以提供更多代码,那么正在发生的事情可能会更加明显。
您应该将opencv_imgproc220.dll(如果使用emgu cv 2.2.1.1150)粘贴到项目bin / debug文件夹中。
或者,如果您不想使用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
一种简单的方法是在构造函数中传递彩色图像的BitMap;
Image<Bgr, byte> inputImage = //your original bgr image
Image<Gray, Byte> result = new Image<Gray,byte>(inputImage.Bitmap);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.