Capturing the Number Plates of the Vehicles Using OpenCV Haarcascade files.
Abstract
Capturing the number plates of a vehicle is a very important task and can be used in many ways like when someone is over speeding, one can just click the image and send it to our program which will extract the number plate and can be used to send fine automatically. This can be developed/ upgraded with multiple use cases. We used haarcascade files to extract number plate from the given image.
Code Description & Execution
Pytesseract
Pytesseract is a tool for Optical Character Recognition (OCR) in python i.e. it helps us read the text in an image. It assumes image to be in RGB format and hence we need to pass images in RGB (red, green, blue) format for good results.
pip install pytesseract to install the package.
- Install pytesseract application for windows from the link given below. You can download 32 bit or 64 bit as per your requirement.
https://github.com/UB-Mannheim/tesseract/wiki
Install using the default options.
2. Search for “tesseract.exe” file in your system. It would ideally be in this location “C:/Program Files (x86)/Tesseract-OCR/tesseract.exe”. You will paste this path in the code.
Haar Cascade files
These are files pre-trained to detect particular objects in an image. The one we are using is specifically trained to detect number plates in an image. It works as a classifier and classifies positive data points(points where we detected and capturing the number plates) and negative data points(where we didn’t detect number plate)
How to Execute?
So, before execution we have some pre-requisites that we need to download or install i.e., anaconda environment, python and a code editor.
Anaconda: Anaconda is like a package of libraries and offers a great deal of information which allows a data engineer to create multiple environments and install required libraries easy and neat.
Refer to this link, if you are just starting and want to know how to install anaconda.
If you already have anaconda and want to check on how to create anaconda environment, refer to this article set up jupyter notebook. You can skip the article if you have knowledge of installing anaconda, setting up environment and installing requirements.txt
1. Install necessary libraries from requirements.txt file provided.
2. Go to the directory where your requirement.txt file is present.
CD<>. E.g, If my file is in d drive, then
- CD D:
- CD D:\License-Plate-Recognition-main #CHANGE PATH AS PER YOUR PROJECT, THIS IS JUST AN EXAMPLE
If your project is in c drive, you can ignore step 1 and go with step 2.
Eg. cd C:\Users\Hi\License-Plate-Recognition-main #CHANGE PATH AS PER YOUR PROJECT, THIS IS JUST AN EXAMPLE
3. Run command pip install -r requirements.txt or conda install requirements.txt
(Requirements.txt is a text file consisting of all the necessary libraries required for executing this python file. If it gives any error while installing libraries, you might need to install them individually.)
All the required files will be downloaded after you run it. I got requirement already satisfied as I already have them installed.
To run the code, start jupyter notebook
Open the folder containing the code, here it is licence-plate-recognition
When you run the number_plate_detection.ipynb file, you get the appropriate results.
Results
Issues Faced
1. Make sure to change the path in the code. Give full path of image on which you want to perform number plate detection.
Click Here To Download This Code And Associated File.