加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-15 17:24:01 所属栏目:百科 来源:网络整理
导读:无论如何要让这件事变得更快?现在,它就像source Image上的6秒,大小为1024×768,模板为50×50左右.这是使用AForge,如果有人知道其他更快更简单的方法请提交. 我要做的任务是在屏幕截图中找到一个较小的图像.最好快我的限制是1秒.我正在寻找的图像是一个红色
无论如何要让这件事变得更快?现在,它就像source Image上的6秒,大小为1024×768,模板为50×50左右.这是使用AForge,如果有人知道其他更快更简单的方法请提交.
我要做的任务是在屏幕截图中找到一个较小的图像.最好快我的限制是1秒.我正在寻找的图像是一个红色矩形简单图像,截图更复杂.

System.Drawing.Bitmap sourceImage = (Bitmap)Bitmap.FromFile(@"C:SavedBMPs1.jpg");
System.Drawing.Bitmap template = (Bitmap)Bitmap.FromFile(@"C:SavedBMPs2.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,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 – matchTemplate函数.
http://opencv.willowgarage.com/wiki/OpenCV_GPU – 关于移植到GPU的OpenCV功能.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读