在调用比较扩展方法时,尝试使用AForge.Imaging、i am getting Template's size should be smaller or equal to source image's size比较两个位图。
public static Boolean Compare(this Bitmap image1, Bitmap image2, double comparisionLevel, float threshold)
{
return new ExhaustiveTemplateMatching(threshold)
.ProcessImage(image1.To24bppRgbFormat(), image2.To24bppRgbFormat())[0]
.Similarity >= comparisionLevel;
}
public static Bitmap To24bppRgbFormat(this Bitmap img)
{
return img.Clone(new Rectangle(0, 0, img.Width, img.Height),
System.Drawing.Imaging.PixelFormat.Format24bppRgb);
}我遗漏了什么?
发布于 2014-02-06 17:57:45
根据您所得到的错误和ExhaustiveTemplateMatching调用的文档,image2看起来比image1大。我不认为您的扩展方法中有任何错误。
总的来说,您的问题似乎与image1和image2本身有关。一种可能的解决方案是添加逻辑以确定哪个图像更大,然后将其中一个作为sourceImage参数传入,另一个作为templateImage传递。
我不知道这个方法如何处理image1更高的情况,但是image2更宽.
免责声明:我从未使用过AForge;我只是从C#的总体知识和方法文档中获得了一些知识。
发布于 2014-07-18 11:45:31
模板图像大小(宽度和高度)必须小于要比较的图像。
首先要做的是这样的事情:
if(templateImage.Height > uploadedImage.Height || templateImage.Width > uploadedImage.Width)
uploadedImage = ResizeImage(uploadedImage, uploadedImage.Height, templateImage.Width)你可以找到很多ResizeImage的实现--我觉得这个很有趣(https://stackoverflow.com/a/6501997/3852812),你只需要用Math.Max代替Math.Min
https://stackoverflow.com/questions/21610203
复制相似问题