2

I am developing an anpr application and I have managed to locate the number plate area from the vehicle image. Following is the numberplate image i h ave extracted

when i feed this image to tesseract OCR engine it seems to detect a character "L" before "C" so im thinking of taking out the remaining black pixels around the number plate area. is there a particular approach that i can take to sort this out? I am using aforge.net library in this case

Cheers

Mr.Noob
  • 1,005
  • 3
  • 24
  • 58
  • well if there's always 1 L prefixed to your result why not just ignore the first L? :-) – mtijn Aug 03 '12 at 11:38
  • well this is just one number plate and one case.the OCR engine seems to consider the black area as part of the character i suppose. so my issue is to eliminate the black pixel area around the number plate – Mr.Noob Aug 03 '12 at 11:42

1 Answers1

5

One approach for semi-automatically removing the black pixel areas around the number plate could be to apply the PointedColorFloodFill filter four times, placing the flood fill starting points in the four corners of your image.

Here is some example code where I have applied the filter on a copy of the number plate image from your question above (cropped to remove the white border):

var filter = new PointedColorFloodFill();
filter.FillColor = Color.White;
filter.Tolerance = Color.FromArgb(60, 60, 60);

filter.StartingPoint = new IntPoint(0, 0);
filter.ApplyInPlace(image);
filter.StartingPoint = new IntPoint(image.Size.Width - 1, 0);
filter.ApplyInPlace(image);
filter.StartingPoint = new IntPoint(image.Size.Width - 1, image.Size.Height - 1);
filter.ApplyInPlace(image);
filter.StartingPoint = new IntPoint(0, image.Size.Height - 1);
filter.ApplyInPlace(image);

which provides the following image after completed filtering from all four corners:

Flood-filled number plate

You may want to experiment with a more grayish fill color and different tolerance, but this example could at least provide a reasonable starting point.

UPDATE I stumbled across the BradleyLocalThresholding filter which could give you an even better starting point for your OCR recognition. This filter can only be applied to 8bpp images, which you would be able to solve for example by first applying the Grayscale filter on your original image. If you add the following four lines before the PointedColorFloodFill code:

var grayFilter = new Grayscale(0.3, 0.3, 0.3);
var image = grayFilter.Apply(originalImage);

var bradleyfilter = new BradleyLocalThresholding();
bradleyfilter.ApplyInPlace(image);

and reduce the PointedColorFloodFill tolerance to e.g. 10 for each RGB component:

filter.Tolerance = Color.FromArgb(10, 10, 10);

the fully filtered number plate will now look like this:

enter image description here

Anders Gustafsson
  • 15,837
  • 8
  • 56
  • 114
  • tried it but it seem to throw an exception saying Source pixel format is not supported. any idea about it? – Mr.Noob Aug 03 '12 at 15:14
  • 1
    According to documentation 8bpp grayscale and 24bpp color images are supported. To be on the safe side, perhaps you can clone the image to an 8bpp image before applying the filter: `var clonedImg = Image.Clone(origImg, PixelFormat.Format8bppIndexed);` – Anders Gustafsson Aug 03 '12 at 15:17
  • Im a bit lost with this thing. Can you advice me as to what colour ranges i should be using to remove the surrounding black pixels? – Mr.Noob Aug 05 '12 at 17:29
  • 1
    @hypertunes I have added some code to illustrate the flood fill filtering. Hope it is sufficient. – Anders Gustafsson Aug 06 '12 at 10:39
  • 1
    Wow that looks promising to me @Anders. I am at work right now I'll check this out and let you know. Thank you very much for your effort mate! – Mr.Noob Aug 06 '12 at 10:52
  • the filter still seem to throw an exception saying "source pixel format is not supported by this filter". any idea about it? – Mr.Noob Aug 06 '12 at 18:40
  • 1
    Can you make your original image available for download somewhere? Which filter is complaining right now? I realize that the order of my code can be a little confusing; make sure that you first pass the _original_ image to the grayscale filter, and then work on the _grayscale filtered_ image from there on. – Anders Gustafsson Aug 06 '12 at 18:44
  • Hey Anders I managed to sort it out. something was wrong with the indexing of pixels. this seem to work as a charm i also added some closing and openning operations just to remove the remaining black pixel around the text. – Mr.Noob Aug 07 '12 at 00:32
  • just a quick question can you tell me the reason for using image.size.width-1 and with height similarly. As you said the flood filter should be done from all four corners of the image. so how will those arguments work with it? I am just trying to figure out the logic behind using it. – Mr.Noob Aug 07 '12 at 10:26
  • `image.Size.Width - 1` and `image.Size.Height - 1` are the maximum coordinates in image width and height directions, respectively, since the minimum coordinates are `(0, 0)`. I am just placing my start pixels in the four corners using the combinations of these coordinates, and flood fill fills in those directions that are available to it. – Anders Gustafsson Aug 07 '12 at 10:39
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/14990/discussion-between-hypertunes-and-anders-gustafsson) – Mr.Noob Aug 07 '12 at 11:04