不管怎样,让这件事进展得更快?因为现在源图像大小为 1024x768,模板大小为 50x50 大约需要 6 秒。这是使用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);
http://opencv.willowgarage.com/wiki/FastMatchTemplate- 在这里您可以找到使用两个步骤加速模板匹配的有趣想法,首先尝试匹配下采样图像,然后在找到时与具有较小搜索区域的原始图像匹配。
matchTemplate函数中还有模板匹配的opencv实现。该功能移植到GPU上可以得到显着的加速。
请参阅以下内容
http://opencv.willowgarage.com/documentation/cpp/object_detection.html- 匹配模板功能。http://opencv.willowgarage.com/wiki/OpenCV_GPU- 关于移植到 GPU 的 OpenCV 功能。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)