VB.Net图像识别

发布于 2024-10-25 04:34:45 字数 250 浏览 5 评论 0原文

基本上,我想要一个“如果 image.contains(image2)...”之类的东西。例如,如果图像 1: IMAGE 1

被发现包含在图像 2 中:

IMAGE 2

然后它将返回它的 x/y 坐标,这在 VB.Net 中可能吗?

Basically, I want a 'If image.contains(image2)...' sort of thing. For example if image 1:
IMAGE 1

is found to contain in image 2:

IMAGE 2

Then it will return it's x/y co-ordinate, is this possible in VB.Net?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

友谊不毕业 2024-11-01 04:34:45

如果您正在寻找精确匹配,那么您只需循环像素并寻找匹配即可。该方法就像字符串匹配一样简单,只是它是二维的。

当然还有一些优化的空间,但基本上:

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)

If you are looking for an exact match, then you just loop through the pixels and look for a match. The method is as simple as a string match, only it's two dimensional.

There is of course room for some optimisations, but basically:

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)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文