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 was first described in 1994 and 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 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 a car using the saved model.

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.

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.

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.

I have created this site with the help of flask framework, HTML, CSS, and Javascript.

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.




Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Script Communication with GetComponent in Unity

Migrate to Java 11 with the help of Nicolai Parlog — Parts 1 & 2

What are Pods in Kubernetes?

Objective-C use Contacts.framework get Contacts

120 Python Projects with Source Code

#11 Using image data, predict the gender and age range of an individual in Python

Sorting Out Feeling(s) with Ruby

What is AWS?

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Anjali Singh

Anjali Singh

More from Medium

Sending Text Messages via Twilio/Python

[C++Algorithm] Travelling Salesman Problem Implementation in C++

Creating a Recognition Code From Scratch

Why Automate? Reliability Approaches with the VMware NSX-T API