Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#1.0 C#
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 ??
Posted 30-Jan-13 7:14am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
Comments
Sergey Alexandrovich Kryukov at 30-Jan-13 14:44pm
   
You are very welcome to come back, of course, but you should at least start finding and reading AForge.NET documentation.
 
You see, I started to use this library for my real work just a week or two before you asked your questions on the topic; and it worked very well for me. I never had to ask anyone. If I could do it, you can, too.
 
—SA
lovely phantom at 30-Jan-13 14:48pm
   
:)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 328
1 Sergey Alexandrovich Kryukov 295
2 Gihan Liyanage 292
3 ClimerChinna 232
4 Abhinav S 192
0 Sergey Alexandrovich Kryukov 8,213
1 OriginalGriff 7,089
2 CPallini 2,598
3 Richard MacCutchan 1,925
4 Abhinav S 1,778


Advertise | Privacy | Mobile
Web04 | 2.8.140826.1 | Last Updated 30 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100