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

发布于 2024-09-03 08:58:52 字数 260 浏览 7 评论 0原文

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

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

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

问候 阿迈勒

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

深者入戏 2024-09-10 08:58:52

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

例如,这是有效的:

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

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

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.

音盲 2024-09-10 08:58:52

,如果您不想使用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

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

通知家属抬走 2024-09-10 08:58:52

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

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

孤云独去闲 2024-09-10 08:58:52

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

Image<Bgr, byte> inputImage = //your original bgr image
Image<Gray, Byte> result = new Image<Gray,byte>(inputImage.Bitmap);

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文