You are on page 1of 21

MACHINE LEARNING

OPENCV AND PYTHON


REAL-TIME LICENSE PLATE RECOGNITION
USING OPENCV AND PYTHON
INTRODUCTION:
• Recognizing vehicle number plates is a difficult but
much needed system. This is very useful for
automating toll booths, automated signal breakers
identification and finding out traffic rule breakers.
• Here we propose a Raspberry Pi based vehicle
number plate recognition system that automatically
recognizes vehicle number plates using image
processing.
• The system constantly processes incoming camera
footage to detect any trace of number plates.
• On sensing a number plate in front of the camera,
it processes the camera input, extracts the number
plate part from the image.
• Processes the extracted image using OCR and
extracts the number plate number from it.

1
Components Required
•Raspberry Pi

•Pi Camera
 
Here only Raspberry Pi and Pi camera are used to build this Raspberry Pi
Plate Recognition System. We previously used Pi camera with Raspberry pi,
and built few projects using it like 
Web Controlled Raspberry Pi Surveillance Robot, IoT
based Smart Wi-Fi doorbell, Smart CCTV Surveillance System, etc.

1
PRE-REQUISITES FOR NUMBER PLATE
RECOGNITION OPENCV PYTHON
Here we use the OpenCV library to
detect and recognize number plates,
and the Tesseract library is used to
read the characters. So before
proceeding further, first install the
OpenCV, Tesseract, and other required
libraries. We previously used OpenCV
in Face Recognition using the
Raspberry Pi project.
INSTALLING OPENCV IN RASPBERRY PI

pip install opencv-contrib-python


OCR AND TESSERACT
What is Optical Character Recognition?
Optical character recognition (OCR) refers to
the process of electronically extracting text
from images (printed or handwritten) or
documents in PDF form. This process is also
known as text recognition.

What is Tesseract?
Tesseract is a tool originally developed by
Hewlett Packard between 1985 and 1994, with
some changes made in 1996 to port to
Windows, and some C++ izing in 1998.
Tesseract became open-source by HP in 2005,
and Google has been further developing it since
2006.

Tesseract recognizes and reads the text present


in images. It can read all image types  —  png,
jpeg, gif, tiff, bmp, etc. It is also widely used to
process everything from scanned documents.
1
INSTALLING OCR AND
TESSERACT
Installing Tesseract 
To install the Tesseract, first, configure the Debian Package (dpkg) using the below command:

sudo dpkg - -configure –a


 
After that, install the Tesseract OCR (Optical Character Recognition) using the apt-get option.

sudo apt-get install tesseract-ocr


 
After that, install the pytesseract using the pip.

pip install pytesseract


 
INSTALLING IMUTILS

imutils is used to make


essential image
processing functions such
as translation, rotation,
resizing, skeletonization
easier with OpenCV. Use
the below command to
install the imutils:

pip3 install imutils


Python Programming for Number Plate
Recognition using Raspberry Pi
License plate recognition OpenCV python
code involves three major steps.

• The first step is License Plate Detection.

The contour function will be used to detect the


rectangular objects in the image to find the number

plate.

• The second step is Character


Segmentation. Once Contour detects the License
Plate, we have to crop it out and save it as a new
image.

• And the final step is Character Recognition. We


will perform Optical Character Recognition on the
cropped image to detect the number.

1
LETS LOOK IN TO THE CODE
AND WORKING
At the starting of the code, import the required
packages for this project.
Then initialize the camera object and set the resolution at
(640, 480) and the frame rate at 30 fps.
Then use the capture_continuous function to start capturing
the frames from the Raspberry Pi camera. We are using the
keyboard key ‘S’ to capture a particular frame.
When the keyboard key is pressed, it will take the last frame.
After capturing the last frame, it will use a bilateral
filter function to remove the unwanted details from the
captured image.
After removing the unwanted details, use the Canny Edge
Method to perform edge detection.

Now we will look for contours on our image. After that sort the detected
contours from big to small.
The Raspberry Pi can find multiple contours, so we have to filter the
license plate contour by searching for a rectangle shape contour
with four sides and a closed figure among the obtained results.
After finding the license plate, mask everything except the
license plate
After masking the entire image except the license plate
region, we will crop out the license plate area and save it as a
new image.
When the keyboard key is pressed, it will take the last frame.
After capturing the last frame, it will use a bilateral
filter function to remove the unwanted details from the
captured image.
Now in the final step, read the characters from the license plate
image using the Tesseract library and store the recognized
characters in the ‘text’ variable. As mentioned earlier, we are
also sending a mail when Pi detects a license plate. So the
license plate information will be sent to the mentioned email
address. The code for sending the mail is given below.
THANK YOU ANY QUERIES ?

You might also like