比较模板和表单c#的相等性

时间:2014-09-05 13:30:03

标签: c# bitmap equality rectangles aforge

我试图比较2位图中矩形的相等性。我正在使用AForge库。一个是模板,另一个是表单。我试过这个,但它对我来说似乎很粗糙,因为它有很多迭代,这使得程序非常慢。它的工作原理但问题是由于迭代次数过多,程序会挂起。请问有什么我想念的吗?我是在正确的轨道上还是什么?请帮助并原谅我下面的原始代码。  位图位图=新位图(pictureBox1.Image);             位图bitmap2 =新位图(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");
                            }.....

1 个答案:

答案 0 :(得分:0)

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