2011-03-20 181 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)