比较模板和c#形式的相等性

本文关键字:比较 | 更新日期: 2023-09-27 18:20:50

我试图比较两个位图中矩形的相等性。我在使用AForge图书馆。一个是模板,另一个是表单。我试过这个,但对我来说似乎很粗糙,因为它有太多的迭代,这使得程序非常慢。它是有效的,但问题是程序由于迭代次数过多而挂起。求你了,我缺什么了吗?我是不是走对了路?请帮帮我,原谅我下面的粗制滥造的代码。位图位图=新位图(pictureBox1.Image);位图位图2=新位图(pictureBox2.Image);

        // create an instance of blob counter algorithm
        BlobCounter blobCounter = new BlobCounter();
        blobCounter.MinWidth = 5;
        blobCounter.MinHeight = 5;
        blobCounter.FilterBlobs = true;
        blobCounter.ObjectsOrder = ObjectsOrder.Size;
        blobCounter.ProcessImage(bitmap);
        BlobCounter blobCounter2 = new BlobCounter();
        blobCounter2.MinWidth = 5;
        blobCounter2.MinHeight = 5;
        blobCounter2.FilterBlobs = true;
        blobCounter2.ObjectsOrder = ObjectsOrder.Size;
        blobCounter2.ProcessImage(bitmap2);

        Rectangle[] rects = blobCounter.GetObjectsRectangles();
            Rectangle[] rects2 = blobCounter2.GetObjectsRectangles();
        foreach (Rectangle recs in rects)      
        foreach (Rectangle recs2 in rects2)
            if  (rects.Length > 0 )
            {
                if (rects2.Length > 0)
                {
                    for (int x = 0; x < recs.Width & x < recs.Height; x++)
                    {
                        // for (int x2 = 0; x2 < recs2.Width; x2++)
                        for (int y = 0; y < recs2.Width & y < recs2.Height; y++)
                        {
                            //   for (int y2 = 0; y2 < recs2.Height; y2++)
                            if (recs.Equals(recs2))
                            {
                                this.Refresh();
                                //listBox1.Items.Add("TRUE");
                                Console.WriteLine("TRUE");

                            }
                            else
                            {
                                //listBox1.Items.Add("FALSE");
                                Console.WriteLine("FALSE");
                            }.....

比较模板和c#形式的相等性

在AForge.Net中,您可以尝试从一个图像(位图)中拾取矩形,并尝试使用TemplateMathing方法在位图2中查找类似的矩形。这可能会更快。