开发者

VB.Net Image Recognition

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

VB.Net Image Recognition

is found to contain in image 2开发者_如何学编程:

VB.Net Image Recognition

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


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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜