尝试在调用比较扩展方法时使用AForge.Imaging
,i am getting Template's size should be smaller or equal to source image's size
比较2位图。AForge图像比较
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);
}
我在想什么?
我没有看到任何副手,看起来会导致错误。你确定你的扩展方法是错误的根源吗?有可能扩展方法工作正常,但是'ProcessImage'不喜欢传递给它的值。我建议将'img.Clone'的结果设置为局部变量,然后返回,然后尝试调试应用程序。如果'To24bppRgbFormat'没有抛出异常,那么你可以看到它实际返回的值,这可能会帮助你解决问题。 –