【发布时间】:2019-11-28 08:30:55
【问题描述】:
我正在尝试将图像与模板主图像匹配。所有图像的大小都相同,但图像中的斑点图案会发生变化。
我在 aforge 中尝试了 thresholdfilter,当缺陷表中的 blob 与模板图像完美对齐时,它可以很好地发现差异。如果有一点点变化,所有的 blob 都会被检测为缺陷(不同)。
var img1 = AForge.Imaging.Image.FromFile(@"compare2.jpg");
var img2 = AForge.Imaging.Image.FromFile(@"compare1.jpg");
// (* calculate absolute difference *)
var difference = new AForge.Imaging.Filters.ThresholdedDifference(15)
{OverlayImage = img1}
.Apply(img2);
// (* create and initialize the blob counter *)
var bc = new AForge.Imaging.BlobCounter();
bc.FilterBlobs = true;
bc.MinWidth = 5;
bc.MinHeight = 5;
// (* find blobs *)
bc.ProcessImage(difference);
// (* draw result *)
BitmapData data = img2.LockBits(
new Rectangle(0, 0, img2.Width, img2.Height),
ImageLockMode.ReadWrite, img2.PixelFormat);
Pen redPen = new Pen(Color.Red, 2);
foreach (var rc in bc.GetObjectsRectangles())
AForge.Imaging.Drawing.Rectangle(data, rc, Color.Red);
img2.UnlockBits(data);
imageBox1.Image = img2;
如何对齐 2 张图像以使图案始终完美对齐?
【问题讨论】:
-
在主图像中找到第一个 blob 的坐标,然后在第二个图像中找到第一个 blob 的坐标并移动图像,使这些坐标相同。
-
你用谷歌搜索过“图像对齐”吗?有很多不同的方法可以做到这一点!
-
@Andrey ,我确实使用 aforge 中的 blob 计数器找到了 master 中第一个 blob 和第二个图像的坐标,但是如何移动图像?你能分享一些代码sn-p或链接吗?
标签: c# opencv emgucv aforge accord.net