如何检查徽标/图像是否在图像中?
问题描述:
我想比较文档的图像与徽标类型或其他图片,以查看徽标是否在文档中。如何检查徽标/图像是否在图像中?
这样做的应用程序将使用ASP.NET MVC 3和C#。
更多搜索后我瑶池与位图的扩展,使用AForge的解决方案:
public static class BitmapExtensions
{
/// <summary>
/// See if bmp is contained in template with a small margin of error.
/// </summary>
/// <param name="template">The Bitmap that might contain.</param>
/// <param name="bmp">The Bitmap that might be contained in.</param>
/// <returns>You guess!</returns>
public static bool Contains(this Bitmap template, Bitmap bmp)
{
const Int32 divisor = 4;
const Int32 epsilon = 10;
ExhaustiveTemplateMatching etm = new ExhaustiveTemplateMatching(0.9f);
TemplateMatch[] tm = etm.ProcessImage(
new ResizeNearestNeighbor(template.Width/divisor, template.Height/divisor).Apply(template),
new ResizeNearestNeighbor(bmp.Width/divisor, bmp.Height/divisor).Apply(bmp)
);
if (tm.Length == 1)
{
Rectangle tempRect = tm[0].Rectangle;
if (Math.Abs(bmp.Width/divisor - tempRect.Width) < epsilon
&&
Math.Abs(bmp.Height/divisor - tempRect.Height) < epsilon)
{
return true;
}
}
return false;
}
}
答
我认为你要使用模板匹配功能。我会建议使用opencv。这是similar to this question
+0
是的,但没有一个工作的答案... – RickardP 2013-02-20 17:18:12
http://www.whathaveyoutried.com? – rekire 2013-02-18 16:50:42
没有因为我不知道从哪里开始... – RickardP 2013-02-20 17:18:35