2012-02-25 22 views
4

無論如何可讓這件事情變得更快?因爲現在它就像是6秒鐘的sourceImage,大小爲1024x768,模板爲50x50左右。這是使用AForge,如果有人知道其他更快,相當簡單的方式,請提交。 我試圖做的任務是在屏幕截圖中找到較小的圖像。最好快一點我的限制是1秒。我正在尋找的圖像是一個紅色的矩形簡單的圖像,截圖更復雜。在另一個大圖像內找到較小的圖片並快速

System.Drawing.Bitmap sourceImage = (Bitmap)Bitmap.FromFile(@"C:\SavedBMPs\1.jpg"); 
System.Drawing.Bitmap template = (Bitmap)Bitmap.FromFile(@"C:\SavedBMPs\2.jpg"); 
// create template matching algorithm's instance 
// (set similarity threshold to 92.5%) 

ExhaustiveTemplateMatching tm = new ExhaustiveTemplateMatching(0.921f); 
// find all matchings with specified above similarity 

TemplateMatch[] matchings = tm.ProcessImage(sourceImage, template); 
// highlight found matchings 

BitmapData data = sourceImage.LockBits(
    new Rectangle(0, 0, sourceImage.Width, sourceImage.Height), 
    ImageLockMode.ReadWrite, sourceImage.PixelFormat); 
foreach (TemplateMatch m in matchings) 
{ 

     Drawing.Rectangle(data, m.Rectangle, Color.White); 

    MessageBox.Show(m.Rectangle.Location.ToString()); 
    // do something else with matching 
} 
sourceImage.UnlockBits(data); 
+0

你可以發佈一些exaples? – BlackBear 2012-02-25 12:14:09

+0

圖片的例子? – 2012-02-25 12:14:50

+0

圖片示例不能做:它說我需要超過10的聲望才能做到這一點。我現在只有4個 – 2012-02-25 12:21:47

回答

2

http://opencv.willowgarage.com/wiki/FastMatchTemplate - 在這裏你可以找到使用兩個步驟加快模板匹配有趣的想法,首先會嘗試下采樣圖像,發現比賽的時候,原有的較小的搜索區域。

在matchTemplate函數中還有opencv模板匹配的實現。這個功能被移植到可以顯着加速的GPU上。

請參見下面的

http://opencv.willowgarage.com/documentation/cpp/object_detection.html - matchTemplate功能。 http://opencv.willowgarage.com/wiki/OpenCV_GPU - 關於移植到GPU的OpenCV功能。

+0

Gpu可能在服務器上有問題。 Fe主機服務器和幾乎沒有VPS有GPU訪問;(可悲的是, – TomTom 2012-02-27 10:16:43

+1

你是對的,無論如何,從第一個鏈接下采樣的伎倆可以使沒有GPU實現足夠的加速 – 2012-02-27 11:15:40

+0

@MichaelKupchick哇.........這是沉重的東西....我需要獲得更多關於圖像的想法和所有謝謝感謝。我不知道它現在是否有效,但讓我檢查一下,如果它匹配,我會投你的答案。希望不要花太長時間。 – 2012-02-27 13:18:05

相關問題