2012-02-25 53 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

相关问题