Automatic Number Plate Recognition using CNN
Automatic Number Plate Recognition systems come in all shapes and sizes:
- And even more, advanced ANPR systems use specialized neural network architectures to pre-process and clean images before they are OCR’d, thereby improving ANPR accuracy.
- Automatic Number Plate Recognition (ANPR/ALPR) is a process involving the following steps:
- Step #1: Detect and localize a license plate in an input image/frame.
- Step #2: Extract the characters from the license plate.
- Step #3: Apply some form of Optical Character Recognition (OCR) to recognize the extracted characters.
Step 1: Importing the libraries
import cv2
from matplotlib import pyplot as plt
import numpy as np
import imutils
import easyocr
Step 2: Number plate detection
Let’s start simply by importing a sample image of a car with a license plate and define some functions:
The above function works by taking image as input, then applying ‘haar cascade’ that is pre-trained to detect Indian license plates.
output image with detected plate highlighted
output image of detected license plate.
Step 4:Performing some image processing on the License plate.
The below function takes in the image as input and performs the following operation on it-
- resizes it to a dimension such that all characters seem distinct and clear
- convert the colored image to a grey scaled image i.e instead of 3 channels (BGR), the image only has a single 8-bit channel with values ranging from 0–255 where 0 corresponds to black and 255 corresponds to white. We do this to prepare the image for the next process.
- now the threshold function converts the grey scaled image to a binary image i.e each pixel will now have a value of 0 or 1 where 0 corresponds to black and 1 corresponds to white. It is done by applying a threshold that has a value between 0 and 255, here the value is 200 which means in the grayscaled image for pixels having a value above 200, in the new binary image that pixel will be given a value of 1. And for pixels having value below 200, in the new binary image that pixel will be given a value of 0.
- The image is now in binary form and ready for the next process Eroding.
Eroding is a simple process used for removing unwanted pixels from the object’s boundary meaning pixels that should have a value of 0 but are having a value of 1. It works by considering each pixel in the image one by one and then considering the pixel’s neighbor (the number of neighbors depends on the kernel size), the pixel is given a value 1 only if all its neighboring pixels are 1, otherwise it is given a value of 0. - The image is now clean and free of boundary noise, we will now dilate the image to fill up the absent pixels meaning pixels that should have a value of 1 but are having value 0. The function works similar to eroding but with a little catch, it works by considering each pixel in the image one by one and then considering the pixel’s neighbor (the number of neighbors depends on the kernel size), the pixel is given a value 1 if at least one of its neighboring pixels is 1.
- The next step now is to make the boundaries of the image white. This is to remove any out of the frame pixel in case it is present.
- Next, we define a list of dimensions that contains 4 values with which we’ll be comparing the character’s dimensions for filtering out the required characters.
- Through the above processes, we have reduced our image to a processed binary image and we are ready to pass this image for character extraction.
Step 5: Segmenting the alphanumeric characters from the license plate.
Step7: Creating a web portal using python code for detecting a number plate and characters on number plate of the car and sending the detail of car owner of which is not in parking area.
!!!Thanks for reading this article😃!!!