【问题标题】:Compare the equality of a template and form c#比较模板和表单的相等性c#
【发布时间】:2014-10-30 11:28:05
【问题描述】:

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


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-15
      相关资源
      最近更新 更多