【问题标题】:How to convert Image<Gray, Byte> to Image<Gray, float>?如何将 Image<Gray, Byte> 转换为 Image<Gray, float>?
【发布时间】:2012-05-24 05:35:31
【问题描述】:

我正在尝试从另一张图片中减去 1 张图片,有点像这样:

Image<Gray, float> result, secondImage;
Image<Gray, byte> firstImage;
result = firstImage - secondImage;

但它给出了一个错误

Operator '-' cannot be applied to operands of type 'Emgu.CV.Image<Emgu.CV.Structure.Gray,byte>' and 'Emgu.CV.Image<Emgu.CV.Structure.Gray,float>'

也许我需要将 firstImage 转换为 Image&lt;Gray, float&gt; 类型。但我不知道该怎么做。

【问题讨论】:

    标签: c# emgucv


    【解决方案1】:

    引用the documentation

    颜色和深度转换

    在不同颜色和深度之间转换图像很简单。比如你有Image img1,你想把它转换成Single的灰度图,你只需要

    Image<Gray, Single> img2 = img1.Convert<Gray, Single>();
    

    所以,在你的情况下,你可以使用

    result = firstImage.Convert<Gray, float>() - secondImage;
    

    【讨论】:

    • 免责声明:我以前从未见过或使用过 emgucv,只是通过谷歌搜索和阅读得到了这个答案。 (是的,这有点像“你也可以这样做!”轻推。)
    • @Heinzi ... 现在这是 Google 对该问题的第一个搜索结果!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-28
    • 2022-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-25
    相关资源
    最近更新 更多