【问题标题】:Conversion to grayscale using emguCV in C#在 C# 中使用 emguCV 转换为灰度
【发布时间】:2011-02-26 09:10:07
【问题描述】:

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

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

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

问候 阿马尔

【问题讨论】:

  • Tom Wright 的回答对我有用。如果它对您有用,请接受答案。

标签: c# emgucv grayscale


【解决方案1】:

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

例如,这是可行的:

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

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

【讨论】:

    【解决方案2】:

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

    【讨论】:

      【解决方案3】:

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

      【讨论】:

      • 这个答案看起来很愚蠢,但它是正确的答案。我在 ILSpy 中检查了 ColordImage.Convert(),该函数使用 Image.ConvertColor(),其中包含捕获所有内容的 try/catch 块,包括 dll 加载错误。
      【解决方案4】:

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-06-07
        • 1970-01-01
        • 2018-04-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-05-05
        • 1970-01-01
        相关资源
        最近更新 更多