This weekend I set a goal to make a license plate recognizer in 2 days. This is my first image processing project. I've worked with most of the libraries featured on this project before, but for smaller and different things. This is a simple solution, using a very curated set of images (good quality, parked cars, good lighting, etc.). I'm being not so careful with the image filters, thresholds, and the filtering of the contours since I just wanted to learn how all this works- if I wanted to make it work for a bigger quantity of pictures I know exactly which parts I would have to nitpick, and I don't think it's worth it. Now let's get to the procedure.
Let's use this picture as an example.
First step is turning it into a grayscale image:
Now we can apply a threshold to it, and look how defined the license plate looks:
Then using opencv we detect the contours:
And now we filter them by aspect ratio, width and height. In 21 of the 25 pictures that was enough for keeping just the license plate contours, but in 4 cases like the one below 2 contours were kept. In all of those cases the license plate was below the other shape, so I decided to just keep the lowest one.
Now we can crop the license plate out of the image:
And once again grayscale it and apply a threshold
Now using an skimage function we remove the borders, invert the image, and this is the final result:
We can already feed this picture to pytesseract and it succesfully recognizes the characters.