C# 大图像比较

C# 大图像比较,c#,bitmap,aforge,C#,Bitmap,Aforge,尝试使用a RGE.Imaging比较两个位图时,调用比较扩展方法时,我得到的模板大小应小于或等于源图像的大小 public static Boolean Compare(this Bitmap image1, Bitmap image2, double comparisionLevel, float threshold) { return new ExhaustiveTemplateMatching(threshold)

尝试使用
a RGE.Imaging
比较两个位图时,
调用比较扩展方法时,我得到的模板大小应小于或等于源图像的大小

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);
        }

我遗漏了什么?

根据您收到的错误和呼叫文档,看起来
image2
image1
大。我认为你的扩展方法没有任何错误

总体而言,您的问题似乎与
image1
image2
本身有关。一种可能的解决方案是添加逻辑以确定哪个图像更大,然后将该图像作为
sourceImage
参数传入,另一个作为
templateImage
传入

我不知道该方法如何处理image1更高的情况,但image2更宽

免责声明:我从未使用过Forge;我只是从总体的C#知识和简单的方法文档中收集信息。

模板图像大小(宽度和高度)必须小于要比较的图像

首先要做的事情如下:

if(templateImage.Height > uploadedImage.Height || templateImage.Width > uploadedImage.Width)
    uploadedImage = ResizeImage(uploadedImage, uploadedImage.Height, templateImage.Width)

你可以找到很多ResizeImage的实现,我觉得这一个很有趣(),你只需要用Math.Max替换Math.Min,我看不到任何会导致错误的东西。您确定扩展方法是错误的来源吗?扩展方法可能工作正常,但
ProcessImage
不喜欢传递给它的值。我建议将
img.Clone
的结果设置为局部变量,然后返回该变量,然后尝试调试应用程序。如果
To24bppRgbFormat
没有抛出异常,那么您可以看到它实际返回的值,这可能会帮助您解决问题。这很有帮助,谢谢,我认为它在内部处理了所有这些问题,至少我现在知道有什么问题了对两个图像进行简单的区域检查可能对您有用,尽管仍然存在一个问题,一个更高,另一个更宽。一个图像甚至可能不支持这些类型的比较。是的,这是比较两个相同大小的图像或一个图像本身的问题