基本上,我想要一个'If image.contains(image2)...'之类的东西。例如,如果图像 1:
发现包含在图像2中:
然后它将返回它的 x/y 坐标,这在 VB.Net 中可能吗?
基本上,我想要一个'If image.contains(image2)...'之类的东西。例如,如果图像 1:
发现包含在图像2中:
然后它将返回它的 x/y 坐标,这在 VB.Net 中可能吗?
如果您正在寻找精确匹配,那么您只需遍历像素并寻找匹配。该方法与字符串匹配一样简单,只是它是二维的。
当然还有一些优化的空间,但基本上:
For y = 0 To image.Height - image2.Height - 1
For x = to image.Width - image2.Width - 1
ix = 0
iy = 0
cnt = 0
While iy < image2.Height And ix < image2.Width And image.GetPixel(x + ix, y + iy) = image2.GetPixel(ix, iy) Then
cnt += 1
ix += 1
If ix = image2.Width Then
ix = 0
iy += 1
End If
End While
If cnt = image2.Width * image2.Height Then
Return New Point(x, y)
End If
Next
Next
Return New Point(-1, -1)