2
我想比較文檔的圖像與徽標類型或其他圖片,以查看徽標是否在文檔中。如何檢查徽標/圖像是否在圖像中?
這樣做的應用程序將使用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;
}
}
http://www.whathaveyoutried.com? – rekire 2013-02-18 16:50:42
沒有因爲我不知道從哪裏開始... – RickardP 2013-02-20 17:18:35