本文介绍了穷举模板匹配有错误'索引超出了数组的范围'。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想匹配两个具有相同特征的图像。 I 使用Aforge.Net的穷举模板匹配来做到这一点。当我比较相同的图像并给出相似值1时,它会起作用,但是我得到一个错误 索引超出了数组 b
I want to match two image which have same characteristic. I use Exhaustive Template Matching from Aforge.Net to do that. It work when i compare same image and give 1 for similarity value, but i getting an error Index was outside the bounds of the array in
akurasiBox.Text = matchings[0].Similarity.ToString();
这是代码
This is the code
private void kenali_citra_Click(object sender, EventArgs e)
{
pictureBox3.Image.Save(@"E:\bismillah\bismillah\temp.jpg", ImageFormat.Jpeg);
ExhaustiveTemplateMatching tm = new ExhaustiveTemplateMatching();
System.Drawing.Image z = System.Drawing.Image.FromFile(@"E:\SKRIPSI\bismillah\bismillah\temp.jpg");
Rectangle cloneRects = new Rectangle(0, 0, mybitmaps.Height, mybitmaps.Width);
PixelFormat formats = pictureBox3.Image.PixelFormat;
Bitmap clonebitmaps = mybitmaps.Clone(cloneRects, PixelFormat.Format8bppIndexed);
Bitmap cUji = clonebitmaps;
System.Drawing.Image a = System.Drawing.Image.FromFile(@"E:\bismillah\Citra Template Terproses\07.jpg");
Bitmap MB = new Bitmap(a);
Rectangle cloneRect = new Rectangle(0, 0, MB.Height, MB.Width);
Bitmap clonebitmap = MB.Clone(cloneRect, PixelFormat.Format8bppIndexed);
Bitmap cTemp = clonebitmap;
{
TemplateMatch[] matchings = tm.ProcessImage(cUji, cTemp);
akurasiBox.Text = matchings[0].Similarity.ToString();
}
}
请帮助解决我的问题。
推荐答案
;
akurasiBox.Text = matchings.Length == 0? "不匹配" :matchings [0] .Similarity.ToString();
akurasiBox.Text = matchings.Length == 0 ? "No matches" : matchings[0].Similarity.ToString();
这篇关于穷举模板匹配有错误'索引超出了数组的范围'。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!