【发布时间】:2012-06-27 14:55:34
【问题描述】:
我对图像处理相当陌生,最近发现了 AForge 库。我一直在尝试在 2 张图像之间进行基本比较,我希望它返回它们之间的相似度百分比。但是,由于有一个空数组,我经常收到一个 Index Out of Bounds 异常,但我不确定为什么ex.ProcessImage 返回一个空数组。我几乎复制了文档中提供的示例代码,但我仍然遇到错误。这是我的代码:
static class Run
{
public static void go()
{
string filename1 = null;
string filename2 = null;
filename1 = "a.a.jpg";
filename2 = "b.b.jpg";
Bitmap image1 = new Bitmap(filename1);
Bitmap image2 = new Bitmap(filename2);
ExhaustiveTemplateMatching ex = new ExhaustiveTemplateMatching( 0 );
TemplateMatch[] match = ex.ProcessImage (image1, image2);
float similarity = match[0].Similarity; //where the error occurs
Console.WriteLine("They are" + similarity + "% similar.");
}
}
我唯一能想象的就是我如何制作位图。但是,我相信我做对了。我也尝试了其他初始化位图的方法,但仍然收到相同的错误。
这可能是我没有意识到的一些愚蠢的错误,但我们将不胜感激。
【问题讨论】:
-
我从来没有弄清楚是什么导致了这个问题,但我用完全相同的代码创建了一个新项目并且它工作正常。所以,这个问题不再需要回答了。
标签: c# image image-processing indexoutofboundsexception aforge