# Licence plate detection with different backgrounds

I just studied the Algorithm of ANPR (Automatic Number Plate Recognition) from the chp 5 of book Packtpub.Mastering.OpenCV.with.Practical.Computer.Vision.Projects in which they detect the vehicle licence plate , but their are some restriction in that algorithm , i call it restriction because its specific for one country and can not be used in my country , well in that algorithm they use the following algorithms to detect the licence plate area

Sobel filter
Threshold operation (otsu)
Close Morphological operation
Svm classifier


But the thing they used is the background color of licence plate as their keypoint for the recognition and detection , but in my area licence plate have different backgrounds , most common are black , white and green , green is not much common but rarely used , black background used white number and white contain black numbers , they use floodfill algorithm for white background , but what should i use for 2 different backgrounds ? Size of the licence plate and size of character matter in any case ?

Here are the sample images of my regional vehicle's liecence plate

• Could you provide some sample images of your region's license plates? There are alternate methods of foreground/object extraction that may work, but I'd like to see some sample images first. Testing real constraints makes solving many image processing apps more straightforward. Oct 28, 2013 at 4:47
• @Rethunk I update my question and add pictures in it
– ARG
Nov 2, 2013 at 19:50
• @Ahmad, since its been a year... can you share some results of your research work ? Sep 8, 2014 at 4:41

Here are a few ideas:

• First convert from color to grayscale. It looks like you have fairly good contrast already. There are various methods to perform this conversion; choose the simplest at first: gray = (red + green + blue)/3. Quite often you don't need anything better than that. For some applications, using just the green color plane is sufficient.
• If you want the algorithm to operate on black text, but if some images have white or light text on a dark background, reverse the polarity of the grayscale image by swapping grayscale 255 for 0, 254 for 1, and so on until all images have black text on a light-color background. You'll need an algorithm to detect when this is necessary, OR you can run an algorithm on the original grayscale image and on the negative (reversed brightness) image and choose the better result. Keep in mind that the "close" morphological operation has a different meaning for light-on-dark text versus dark-on-light text.
• Investigate some adaptive thresholding methods. Using a global Otsu threshold can be problematic--if possible, you should first have some sort of method to detect regions that are likely to be license plates, and then threshold and binarize those regions only. Thresholding an entire image will likely cause trouble.
• Look into the Stroke Width Transform and improvements upon it. The SWT or equivalent can help either with segmentation, or with identifying likely license plate regions, or possibly even with providing edges useful for identification.
• Since in your region there are only a few color combinations, you might be able to create some method that would could a template for every possible color combination and then try to find a match at each of several image scales. The license plate might be 400 x 250 pixels, or 100 x 65 pixels, or whatever.
• For multiscale operations, consider holding an image pyramid in memory. In some cases you can perform an initial match in the smallest image of the pyramid and work your way down. With some modification you could create an image pyramid has a scaling factor of less than 2 from level to level.
• Pull the sample images into Photoshop or GIMP and play around with the filters. You may be surprised to find a filter that is helpful.
• Whenever possible, work on raw, uncompressed images rather than on JPEGs or other compressed images.
• You may not have much of a choice in hardware, but given the fuzzy look of your "LEA 1956" sample, it'd be nice to have more resolution (more pixels per image) and/or sharper optics and/or a raw image instead of a JPEG.

Try to generate the best possible images that you can with pre-processing before your SVM goes to work. Thresholding is often the weak link here. Thresholding and binarization is a common approach, but when you see how noisy a binary image can be you should think very hard whether that is the kind of image you actually want to process (no matter how many people may claim that this is the standard method and hence the best).

Even if you're already starting with a framework and/or algorithms, I recommend doing a little background reading to gain an understanding of both human reading and the many approaches to OCR:

Character Recognition Systems by Cheriet and others is a good reference (though a few years old now) of the various techniques for Optical Character Recognition.

Reading in the Brain by Stanislas Dehaene gives a good high-level overview of human reading, and covers the range of scripts. It's a relatively fast read, and has references to academic works that are useful.

• Thanks for such a nice explanation +1 , you want to say that first we need to detect the region (liecence plate) and than apply otsu on it ? but in my region there are many sizes of liecence plates as you can see above in samples
– ARG
Nov 3, 2013 at 20:02
• A brute force method would be to check for all possible plate shapes even under perspective distortion. If you can reduce the set of shapes even a little--for example, to "quadrilaterals" or "polygons with six or fewer line segments"--then you can filter your results. Better yet, you might try to first identify image portions of some minimum X by Y size for which the Stroke Width Transform returns a high density of objects of the same stroke width. Nov 5, 2013 at 2:32

Check out OpenALPR (http://www.openalpr.com). It uses Local Binary Patterns (LBP) to identify plate regions -- so it should work independently of background colors.

• Nice! By any chance have you read Computer Vision Using Local Binary Patterns by Pietikainen? If so, was it a useful textbook? Mar 4, 2014 at 0:13