Automatic Number Plate Detection
License Plate Recognition (LPR), also known as Number Plate Recognition (NPR), is an important area of research in smart cities and the Internet of Things (IoT) due to the increasing number of vehicles on the road. To maintain vehicle information for various purposes, automated systems are required, and LPR can help achieve this goal. This research proposes an efficient algorithm for recognizing Indian vehicle number plates that can handle noisy, low-illuminated, cross-angled, and non-standard font plates.
The algorithm uses several image processing techniques such as morphological transformation, Gaussian smoothing, Gaussian thresholding, and Sobel edge detection in the pre-processing stage. Then, number plate segmentation is performed, followed by contour detection based on character dimensions and spatial localization. Finally, Optical Character Recognition (OCR) is applied to recognize the extracted characters. The recognized text is stored in a database, sorted, and made available for searching.
Although the proposed algorithm does not use advanced machine learning or deep learning algorithms, it works efficiently for an average use case. However, it has its limitations and drawbacks.
Requirements
Dataset
Images of Indian vehicles where the number plate is clearly visible.

Applications:
Automatic Number Plate Recognition (ANPR) has a wide range of applications since the license number is the primary, most widely accepted, human readable, mandatory identifier of motor vehicles. Some of the applications are:
Here are some additional examples of how ANPR technology can be used in various applications:
- Housing societies / Apartments: ANPR can be implemented in housing societies and apartments to manage vehicle access for residents. By storing license plate details in a database, the system can automatically allow registered vehicles to enter the premises, reducing the need for manual security checks at the gate.
- Parking: ANPR technology can be used for ticketless parking fee management, parking access automation, vehicle location guidance, parking fee charging, and car theft prevention. It can also help prevent fraud related to lost or changed tickets.
- Access Control: ANPR can bring automation to vehicle access control management, providing increased security and carpool management for logistics. It can also assist with security guide assistance, event logging, event management, access diary keeping, and data analysis. ANPR is especially effective in border and law controls.
- Motorway Road Tolling: ANPR can be used for efficient road tolling, reducing fraud related to non-payment, and minimizing manpower required to process events of exceptions. This can help fund improvements to highways, motorways, roads, and bridges.
- Journey Time Measurement: ANPR can be used to measure journey times by collecting data that can be processed and fed back to road users to increase traffic security, help with efficient law enforcement, optimize traffic routes, and reduce costs and time.
Overall, ANPR technology has a broad range of applications and can be implemented in various industries to improve efficiency, safety, and security.
Methodology
The suggested approach comprises four primary phases: pre-processing, detection, recognition, and searching, as illustrated in the figure below.

Brief description of steps:
Step 1: Image pre-processing
Step 1.1: Noise reduction
Gaussian filtering or smoothing aims to decrease the amount of noise and fine details in an image, which can be beneficial for subsequent image processing steps. Mathematically, a Gaussian filter can be represented as an equation that applies a Gaussian function to each pixel in the image to blur out the noise and fine details. Gaussian filter can be expressed as:

The input image is made to convolve with this 2-D ‘G’ matrix to obtain a smoothened image. In OpenCV, Gaussian smoothing can be applied using the following function:

where (5,5) refers to the filter size and ‘0’ indicates the model to find the value of standard deviation (sigma) itself.
Step 1.2: RGB to Grayscale conversion
Converting a color image from RGB format to grayscale can save a significant amount of time because it allows us to perform image processing operations on a single 2D matrix rather than on multiple matrices for each color channel. This simplifies the process and makes it easier to apply filters such as the Sobel filter for edge detection. Additionally, in edge detection, we are typically interested in changes in intensity rather than color, and these changes are easier to observe and analyze in a grayscale image. Therefore, converting an RGB image to grayscale is a common preprocessing step in many image processing applications.
Step 1.3: Edge detection using Sobel method
The Sobel edge detection technique operates by determining the gradient of the image intensity at each pixel in the image. It identifies the direction with the most significant change from light to dark and the rate at which this change occurs in that direction. The Sobel method employs certain terms to perform edge detection. The following terms are used to perform edge detection using Sobel method:

In OpenCV, cv2.Sobel(img2,cv2.CV_8U,1,0,ksize=3) is used to perform edge detection using kernel size of 3.
Step 1.4: Under-sampling
To ensure a consistent and steady frame rate, the algorithm for number plate detection and recognition needs to be optimized. Image processing algorithms tend to work slower for high-resolution images, which is why it is unnecessary to process images with such high resolution. Therefore, a resolution reduction stage is implemented to down sample the image if it exceeds a certain predetermined threshold. This helps maintain an optimal frame rate for the algorithm.
Step 1.5: Morphological transformation
The Top-hat and Black-hat filters are part of Morphological transformations in image processing. The Top-hat filter is utilized to amplify bright objects of interest within a relatively darker background, whereas the Black-hat filter (also known as bottom-hat) is applied to enhance dark objects of interest in a relatively brighter background. In the current work, the Top-hat filter outcomes are added to the original image, while the Black-hat filter results are subtracted from it.

Step 2: Number plate detection
Step 2.1: Apply Counters
Contour tracing or border following is a commonly used algorithm for generating contours, which are the linked points of equal intensity along the boundary. In OpenCV, contour detection is akin to finding a white object from a black background. Hence, to achieve this, an inversion operation needs to be applied during the adaptive Gaussian thresholding stage. This helps to ensure that the desired white object is isolated and extracted from the black background accurately, without any confusion or noise.
Step 2.2: Filter Contours and extract region of interest
Contours are often used to identify small regions in images, especially sharp edges and noise outliers. While these contours may be unnecessary for a human observer, they need to be filtered out by a program. In our approach, we first applied bounding boxes to each contour and then evaluated several factors for each contour, such as minimum area, width, height, and aspect ratio range. By doing so, we were able to filter out most of the unnecessary contours, bringing us closer to our objective of detecting a number plate.

Step 3: Number plate recognition
Step 3.1: Number plate de-skewing
Skew refers to the degree of rotation required to align an image horizontally and vertically. The amount of skew is usually measured in degrees. Deskewing is a technique used to remove skew by rotating an image in the opposite direction of its skew. This process results in an image that is horizontally and vertically aligned, with the text running across the page instead of at an angle. In our project, we utilize the function ratio_and_rotation() to perform this Deskewing step.
Step 3.2: Pre-process region of interest
In certain cases, two or more contours may overlap completely, such as in the case of the number ‘zero’. This overlap can result in the inner contour being detected separately from its outer contour, potentially leading to errors during the recognition process. To address this issue, we check for overlapping contours and ensure that they are treated as a single entity. Additionally, we may resize the image prior to the recognition step to further improve accuracy.
Step 3.3:Number plate text recognition
Python-tesseract is a powerful OCR tool designed for Python that enables text recognition from images. This tool allows us to recognize and extract text embedded within an image. In our project, we utilized Python-tesseract to perform OCR on the filtered and Deskewed contour, ultimately obtaining the text present within the image.

Challenges and solution:
- Handling images with varying brightness and contrast: To address this issue, we convert RGB images to grayscale, which enhances the visibility of image intensity changes and helps to deal with bright and dark objects.
- Handling noisy images: We address this problem by applying a Gaussian filter during the image pre-processing stage, which helps to reduce the noise present in the image.
- Handling skewed or rotated number plates: To handle images with skewed or cross-angled number plates, we use deskewing, which involves rotating the image to align the number plate horizontally and vertically. This step allows for accurate text detection on the number plate.
- Handling non-standard number plates: Our code is designed to handle standard number plates. However, if the number plate is non-standard or partially torn, our system may not be able to detect it, and it will not be stored in the database. As a result, searching for such plates is not possible.
Conclusion
Although our project did not involve complex machine learning or deep learning algorithms, it can still be implemented effectively in housing societies, apartments, or institutions to regulate vehicle access. Despite some limitations, we were able to successfully overcome most of the challenges encountered during the development process. As a result, the system can efficiently allow registered residents’ vehicles inside the premises.
Contributors
Rohan Katkar
Shubham Kasar
Manan Hude