Search code examples
c#image-processingaforgeautomatic-license-plate-recognition

How to count the number of connected components in a blob using Aforge.Net


In my number plate recognition application(UK number plates) I have done a rectangle detection and I am using several criterion such as width/length ratio of the number plate as well as a minimum width and length of a number plate. I have managed to reduce the non-number plate areas significantly. My last criterion would be to get the number of connected components for each candidate region so that I can verify the true number plate region of the vehicle image which I read this on a research paper.

I am using C# and Aforge.Net library. But how can I use ConnectedComponentsLabeling to obtain the number of connected Components in the number plate?


Solution

  • I'm doing this:

    FiltersSequence preOcr = new FiltersSequence(
        Grayscale.CommonAlgorithms.BT709, 
        new BradleyLocalThresholding());
    
    Bitmap grayscale = preOcr.Apply(original);
    var labels = new ConnectedComponentsLabeling();
    labels.Apply(new Invert().Apply(grayscale));
    
    //Console.WriteLine(labels.ObjectCount);    // Here you go
    foreach (var candidate in labels.BlobCounter.GetObjectsInformation())
    {
        using (Bitmap symbol = new Bitmap(candidate.Rectangle.Width, 
                                          candidate.Rectangle.Height))
        using (Graphics g2 = Graphics.FromImage(symbol))
        {
            g2.DrawImage(grayscale, 0, 0, candidate.Rectangle, GraphicsUnit.Pixel);
            symbol.Save(String.Format(@"temp\{0}-{1}.jpg",i,++n), ImageFormat.Jpeg);
            // do stuff
        }
    }