2011-03-20 171 views
-1

基本上,我想'如果image.contains(image2)...'的东西。例如,如果图像1: IMAGE 1VB.Net图像识别

被发现在图像2包含:

IMAGE 2

然后它会返回它的X/Y坐标,这可能在VB.Net?

+1

几乎所有的东西是可能的;这只是一个努力的问题...... – 2011-03-20 02:11:54

回答

0

如果您正在寻找完全匹配,那么您只需遍历像素并寻找匹配。该方法与字符串匹配一样简单,只是它是二维的。

当然还有余地一些的优化,但基本上是:

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)