如何在AForge.net中过滤掉不需要的blob? [英] How to filter out the unwanted blobs in AForge.net ?

查看:132
本文介绍了如何在AForge.net中过滤掉不需要的blob?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好b $ b

我已经写了一个代码来确定道路上的汽车总数,并且我已经成功了! />


但结果有些图片并不完全正确!!有不必要的斑点,如道路上或车上的反射,它自己!!



如何计算斑点之间的距离以及如何解决这个问题?



------(真)------



原始图片 [ ]



已处理的图片 [ ]



------(false)------



原始图片 [ ]



已处理的图片 [ ]



守则:



Hi
I''ve written a code to determine the total number of cars in a road in terms of it''s lights and I''ve succeeded!

but the result with some pictures not exactly true!! there is unwanted blobs such as reflections on the road or on the car it self !!

how can I calculate the distance between blobs and how to solve this problem ??

------(true)------

the original image[]

the processed image[]

------(false)------

the original image []

the processed image[]

The Code :

///////--------------------------------------------------------////////////
    private void Count_Click(object sender, EventArgs e)
    {

        try
        {

            ////////////////////
            // create filters
            AForge.Imaging.Filters.ContrastCorrection Contrast = new ContrastCorrection(int.MaxValue);
            AForge.Imaging.Filters.BrightnessCorrection Brightness = new BrightnessCorrection(-200);
            // apply the filters
            AForge.Imaging.UnmanagedImage UnManagedImg = AForge.Imaging.UnmanagedImage.FromManagedImage((Bitmap)TargetPic.Image);
            Contrast.ApplyInPlace(UnManagedImg);
            Brightness.ApplyInPlace(UnManagedImg);
            TargetPic.Image = UnManagedImg.ToManagedImage();
            ////////////////////
            // creat instance of BlobCounter
            BlobCounter LightsCounter = new BlobCounter();
            ////////////////////
            LightsCounter.MinHeight = 5;
            LightsCounter.MinWidth = 5;
            LightsCounter.MaxHeight = 20;
            LightsCounter.MaxWidth = 20;
            ////////////////////
            LightsCounter.FilterBlobs = true;
            LightsCounter.ProcessImage((Bitmap)TargetPic.Image);
            ////////////////////
            Blob[] Lights = LightsCounter.GetObjectsInformation();
            ///////////////////
            // create Graphics object to draw on the picture
            Graphics graphics = Graphics.FromImage((Bitmap)TargetPic.Image);
            // creat a pen
            Pen BluePen = new Pen(Color.Blue, 1);
            //////////////////
            // check the lights
            foreach (Blob Light in Lights)
            {
                try
                {
                    List<IntPoint> EP = LightsCounter.GetBlobsEdgePoints(Light);
                    graphics.DrawPolygon(BluePen, ToPointsArray(EP));
                }

                catch (Exception) { MessageBox.Show("Error"); }

            }


            //////////////////
            label.Text = "The Total # Of Cars Is :" + (Lights.Length) / 2;
            BluePen.Dispose();
            graphics.Dispose();
            //////////////////

        }

        catch (Exception) { MessageBox.Show("Load an image !!"); }
    }


    ///////--------------------------------------------------------/////////
      private System.Drawing.Point[] ToPointsArray(List<IntPoint> points)

      {
    System.Drawing.Point[] array = new System.Drawing.Point[points.Count];

    for (int i = 0, n = points.Count; i < n; i++)
    {
        array[i] = new System.Drawing.Point(points[i].X, points[i].Y);
    }

    return array;
       }

    ///////-------------------------------------------------------//////////







如何将此代码改进为使用任何图像并给出真实结果??




How to improve this code to work with any image and give true result ??

推荐答案

您可以通过两种方式完成:blob识别之前和之后。



之前 - 只需使用是另一个过滤器: http ://www.aforgenet.com/framework/docs/html/4a83d944-d776-ba2c-9847-3254fe3dbfdd.htm [ ^ ]



作为回应关于blob识别的第一个问题,我建议你使用亮度和对比度过滤器:

使用Aforge.net进行图像处理>>我需要帮助 [ ^ ]。



如果使用上面引用的过滤器使用blob过滤,则应在 blob过滤之前应用亮度和对比度过滤器。请注意,这个blob过滤与你已经知道的blob枚举无关。



现在,之后:



所以,你可以使用这个blob枚举。 您应该在应用所有其他过滤器后执行此操作。从AForge.NET演示应用程序中,您可以看到每个blob的属性:

http://www.aforgenet.com/framework/docs/html/fd173e0a-647b-6b71-c714-b8ae3cc8bc36.htm [ ^ ]。



因此,您可以随时遍历所有blob的集合,并根据您需要的任何标准删除您不想要进一步考虑的blob。



最后,您可以将此方法与过滤相结合。基本上,过滤标准只能非常简单(通常是块的X / Y大小),但最终选择可以基于您想要的标准,因此使用这两种方法都很有用。



-SA
You can do it in two ways: before blob recognition and after.

Before — just use yes another filter: http://www.aforgenet.com/framework/docs/html/4a83d944-d776-ba2c-9847-3254fe3dbfdd.htm[^]

In response to your first question on blob recognition, I advised you to use brightness and contrasting filters:
image processing using Aforge.net >> I need the help[^].

If you use the blob filtering using the filter referenced above, you should apply those brightness and contrasting filters before blob filtering. Note that this blob filtering has nothing to do with blob enumeration you already know.

Now, after:

So, you can use this blob enumeration. You should do it after all other filters are applied. From the AForge.NET demo application you can see the properties of each blob:
http://www.aforgenet.com/framework/docs/html/fd173e0a-647b-6b71-c714-b8ae3cc8bc36.htm[^].

So, you can always traverse the collection of all blobs and remove the blobs you don''t want for further considerations, based on whatever criteria you need.

Finally, you can combine this approach with filtering. Basically, filtering criteria can only be pretty simple (typically, by X/Y size of a block), but final selection can be based on the criteria you want, so using both approaches can be useful.

—SA


这篇关于如何在AForge.net中过滤掉不需要的blob?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆