In societies and commercial spaces it’s difficult to manage the manual entries of vehicles. In order to solve this problem, we’ve developed a vehicle number plate recognition system which can read number plate.
We need to build a vehicle number plate recognition system which is capable of:
- Taking image/ video process it and extract the number
- We need a raspberry pi with camera module
- Software side we’re using Python, OpenCV, Numpy and Tesseract
In this blog we will be focusing on Number Plate Recognition from an image
- pip install numpy
- pip install opencv-python==4.1.0
- Install tesseract using windows installer available at: https://github.com/UB-Mannheim/tesseract/wiki
- Note the tesseract path from the installation. Find the tesseract.exe path you may find it in either C:/Program Files/Tesseract-OCR/tesseract.exe or C:/Users/USER/AppData/Local/Tesseract-OCR
- pip install pytesseract
- Note: Set the tesseract path in the script before calling image_to_string: pytesseract.pytesseract.tesseract_cmd = ‘<Your Path>\Tesseract-OCR\tesseract.exe’
Image for illustration:
Here we’re using an Indian number plate as a sample.
Code for vehicle number plate recognition:
- We read the image of a car into a variable using opencv. The image is resized according to needs. It is converted to gray scale image to decrease computations. Bilateral filter is added to reduce the noise in the background. We then find the edges in the image using Canny edges.
- We find all the contours (connected components) in the edged image and sort them by their area. We iterate through the contours until we get one with approximately 4 corners (as number plates are rectangular in shape). We then mask the other parts of the image except for the number plate and pass it for character recognition.
- Cropping unnecessary image. Only taking in consideration the Number Plate.
- Using Tesseract and converting image to String. This gives us the number on the number plate which is stored in Text variable.
If you are still facing issue regarding this topic Feel free to Ask Doubts in the Comment Box Below and Don’t Forget to Follow us on 👍 Social Networks😉