2012-08-25 33 views
1

目前我用它來找到一個位圖,發生在另一個圖像在屏幕上,即一個窗口,但它是工具慢,我想它需要1或更少的秒,我是考慮將圖像裁剪成一個部分,即在圖像0,0點處的一個80,60部分,然後在那裏進行搜索,如果它完成了相同的裁剪,但是y + 60並繼續,直到它覆蓋完整圖像它是800 600像素的更快速的方式來檢測大圖像

我目前使用的代碼是:

 public bool findImage(Bitmap small, Bitmap large, out Point location) 
    { 
     //Loop through large images width 
     for (int largeX = 0; largeX < large.Width; largeX++) 
     { 
      //And height 
      for (int largeY = 0; largeY < large.Height; largeY++) 
      { 
       //Loop through the small width 
       for (int smallX = 0; smallX < small.Width; smallX++) 
       { 
        //And height 
        for (int smallY = 0; smallY < small.Height; smallY++) 
        { 
         //Get current pixels for both image 
         Color currentSmall = small.GetPixel(smallX, smallY); 
         Color currentLarge = large.GetPixel(largeX + smallX, largeY + smallY); 
         //If they dont match (i.e. the image is not there) 

         if (!colorsMatch(currentSmall, currentLarge)) 
          //Goto the next pixel in the large image 

          goto nextLoop; 
        } 
       } 
       //If all the pixels match up, then return true and change Point location to the top left co-ordinates where it was found 
       location = new Point(largeX, largeY); 
       return true; 
      //Go to next pixel on large image 
      nextLoop: 
       continue; 
      } 
     } 
     //Return false if image is not found, and set an empty point 
     location = Point.Empty; 
     return false; 
    } 
+0

這可能是有趣的: http://stackoverflow.com/a/11004944/1373170 –

回答

2

既然你正在尋找可以降低採樣率的大畫面,並且下采樣的SM完全匹配所有圖片(但多次,在不同的偏移)。然後搜索下采樣圖片的精確匹配(可能會遞歸)。

你的大圖不聽起來很大,你可能可以通過Boyer-Moore搜索其中一行來逃脫。