我能够将第二张图像转换为相同的比例和方向,现在尝试使用 absdiff
找到该点但由于图像不完全匹配,我在 diff image 上有边缘.
我认为,我需要找到像 n × n 像素这样的区域中的最小差异,而不是具有相同坐标的像素之间的差异。所以问题是:OpenCV 是否有相应的解决方案和/或是否有更好的解决方案?
编辑:使用 threshold
的解决方案和 erode
:
public static Image<Bgr, Byte> Diff(Image<Bgr, Byte> image1,
Image<Bgr, byte> image2,
int erodeIterations=2)
{
return Diff(image1, image2, new Bgr(50, 50, 50), erodeIterations);
}
public static Image<Bgr, Byte> Diff(Image<Bgr, Byte> image1,
Image<Bgr, byte> image2,
Bgr thresholdColor,
int erodeIterations)
{
var diff = image1.AbsDiff(image2);
diff = diff.ThresholdToZero(thresholdColor);
diff = diff.Erode(erodeIterations);
return diff;
}
最佳答案
不确定 OpenCV,但解决这个问题应该不难。对齐两个图像并找到差异图像,就像您已经完成的那样。在差异图像上使用 NxN 滑动窗口,并计算窗口内显着不同的像素数量,即忽略最多 10 个灰度级的差异。找到整个图像上这些总和的最大值,这应该突出显示您需要的内容。
关于c# - 两幅图像之间的差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16607031/