Task Description 📄
In this task :
👉Create a model that will detect a car in a live stream or video and recognize characters on the number plate of the car.
👉Secondly, it will use the characters and fetch the owner's information using RTO APIs.
👉Create a Web portal where all this information will be displayed (using HTML, CSS, and JS)
So basically, I have decided to break this task into 3 steps:
Step1: Car Detection
We will detect our car using the LBPH algorithm.
Local binary patterns (LBP) is a type of visual descriptor used for classification in computer vision. LBP is the particular case of the Texture Spectrum model proposed in 1990. LBP was first described in 1994. It has since been found to be a powerful feature for texture classification; it has further been determined that when LBP is combined with the Histogram of oriented gradients (HOG) descriptor, it improves the detection performance considerably on some datasets. A comparison of several improvements of the original LBP in the field of background subtraction was made in 2015 by Silva et al. A full survey of the different versions of LBP can be found in Bouwmans et al.
The LBP feature vector, in its simplest form, is created in the following manner:
- Divide the examined window into cells (e.g. 16x16 pixels for each cell).
- For each pixel in a cell, compare the pixel to each of its 8 neighbors (on its left-top, left-middle, left-bottom, right-top, etc.). Follow the pixels along a circle, i.e. clockwise or counterclockwise.
- Where the center pixel’s value is greater than the neighbor’s value, write “0”. Otherwise, write “1”. This gives an 8-digit binary number (which is usually converted to decimal for convenience).
- Compute the histogram, over the cell, of the frequency of each “number” occurring (i.e., each combination of which pixels are smaller and which are greater than the center). This histogram can be seen as a 256-dimensional feature vector.
- Optionally normalize the histogram.
- Concatenate (normalized) histograms of all cells. This gives a feature vector for the entire window.
The feature vector can now be processed using the Support vector machine, extreme learning machines, or some other machine learning algorithm to classify images.
LBPH is widely used in facial recognition and texture analysis for fast prediction but it can also be used for image classifiers such as an image of a car.
So now we will get the data set of various cars and train our data via LBPH.
The more the data would be better would be our prediction of a car.
The next step would be to train our LBPH model to detect the cars.
Then we would save our trained model for future use in a yml file.
Now we will write a code to detect the car in a video using the above-saved model.
We can clearly see that the model had detected the car clearly.
Step2: Number Plate Detection
Now, that the image has been extracted from the running video as soon as the car is detected we will need a model to crop the number plate and then detect the text. We can use pytesseract for this work.
Pytesseract or Python-tesseract is an Optical Character Recognition (OCR) tool for python. It will read and recognize the text in images, license plates, etc. Here, we will use the tesseract package to read the text from the given image.
Mainly, 3 simple steps are involved here as shown below:-
- Loading an Image saved from the computer or download it using a browser and then loading the same. (Any Image with Text).
- Binarizing the Image (Converting Image to Binary).
- We will then Pass the Image through the OCR system.
Below is the code to detect the car number plate text with the help of pytesseract.
As expected, our code has detected the number plate in the car image, cropped and converted it into text via OCR.
Step3: API for Vehicle Info
API is the acronym for Application Programming Interface, which is a software intermediary that allows two applications to talk to each other. Each time you use an app like Facebook, send an instant message or check the weather on your phone, you’re using an API.
This time we need an API that will go to the website to retrieve car information when the car number is passed. On further research, we found a website that provides this service for free for up to 9 uses and then uses paid subscriptions.
So we need to create a python code that will go and retrieve data from this site a return back data in string type. First, create an id on this site and save its username. Leave the rest of the work on the python code below.
The output will be as follows:
Web Site Creation
Now we have created all the parts of our code now we need to design a site that will provide these services for public use.
You can get the source code from the GitHub link for everything on this blog attached at the very end of the blog.
Here is a snapshot of the code and folder structure of the web app.
Here is the working of our site…
This task helped me to create an interactive website that can be used by anyone to upload their car video and get the result. It helped me a lot to clear my concepts and know more about computer vision, machine learning, and full-stack development.
Link for GitHub repository: https://github.com/shiv0112/numberplate_web