c# - 在另一个大图像中快速找到一个较小的图像

标签 c# image image-processing imaging aforge

无论如何让这件事变得更快?因为现在在大小为 1024x768 和模板 50x50 左右的 sourceImage 上大约有 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 功能。

关于c# - 在另一个大图像中快速找到一个较小的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9443862/

相关文章:

c# - 在 C# 中添加到 ImageList 时,Image.Tag 为空

android - 大图像导致应用程序崩溃

c++ - 更改图像位图或在图像上绘制位图会导致图像消失

opencv - 应用平滑过滤器(双边、高斯、vs.)和色彩空间

c# - 按类型或字符串类型强类型 Azure 移动服务表对象?

c# - 在 C# 中对小代码示例进行基准测试,可以改进此实现吗?

c# - 使用 .NET 遍历列表以添加元素

Facebook API : how to get different resolution for Profile Pictures?

image - 如何估计将按比例缩小的 JPEG 图像的大小

python - 将 HSV 掩码转换为一组点