如何将Image<Gray, Byte>转换为Image<Gray, float>?

5

我正在尝试从另一张图像中减去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<Gray, float>类型。但我不知道该怎么做。
1个回答

9

引用自文档

Color and Depth Conversion

Converting an Image between different colors and depths are simple. For example, if you have Image img1 and you wants to convert it to a grayscale image of Single, all you need to do is

Image<Gray, Single> img2 = img1.Convert<Gray, Single>();
因此,在您的情况下,您可以使用
result = firstImage.Convert<Gray, float>() - secondImage;

3
声明:我之前从未见过或使用过emgucv,这个答案是通过谷歌搜索和阅读得到的。(是的,这有点像“你也可以做到!”的提示。) - Heinzi
1
@Heinzi...现在这是谷歌对于这个问题的第一个搜索结果! - geometrikal

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接