License Plate Recognition with OpenCV and Tesseract OCR (original) (raw)

Last Updated : 15 Jul, 2025

License Plate Recognition is widely used for automated identification of vehicle registration plates for security purpose and law enforcement. By combining computer vision techniques with Optical Character Recognition (OCR) we can extract license plate numbers from images enabling applications in areas like security, traffic management and toll systems.

One of the most popular tools for OCR is Tesseract an open-source OCR engine developed by Google. Tesseract is capable of recognizing text from various image formats. In this article we'll explore how to implement a basic License Plate Recognition system using OpenCV and Tesseract OCR.

Implementing License Plate Recognition

Here is the step by step implementation of building this model.

1. Installing Tesseract OCR Engine

We need to install Tesseract OCR engine which is essential for text recognition from images. We can do it by below command.

!apt-get update
!apt-get install -y tesseract-ocr

2. Importing Required Libraries

Here we will use OpenCV and pytesseract library.

python `

import cv2 import pytesseract

`

3. Setting Path for Tesseract

This line sets the path to the Tesseract executable.

pytesseract.pytesseract.tesseract_cmd = "/usr/bin/tesseract"

`

4. Function to Detect License Plate Number

We will define this function which will show the image and turn image into grayscale to simplify the processing and reduce computation. After that applies Gaussian blur to smooth the image and reduce noise making edge detection more accurate.

def detect_plate_number(image_path): image = cv2.imread(image_path) plt.imshow(cv2.cvtColor(image, cv2.COLOR_BGR2RGB)) plt.axis('off') plt.show() gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) blurred = cv2.GaussianBlur(gray, (5, 5), 0)

`

5. Edge Detection using Canny and Contours in the Image

We will use Canny edge detection to highlight the edges in the image, making the plate contours clearer and then finds the contours of the objects in the image helping locate potential license plates.

`

6. Approximate Contours and Check for a Rectangle

We will identify and approximates the contours that resemble the shape of a rectangular license plate.

`

7. Extract License Plate and Apply Thresholding

We will extracts the license plate area and applies thresholding to convert it to a binary image for OCR processing.

`

8. OCR to Recognize Plate Number

We will use Tesseract OCR to recognize the text in the license plate image and return the plate number.

`

9. Calling the Function and Displaying the Output

We will call the function to detect the plate number from the given image path and prints the result.

python `

image_path = "car.jpg"

plate_number = detect_plate_number(image_path) print("Detected Plate Number:", plate_number)

`

**Output:

Screenshot-2025-03-24-173929

Number Plate Recognition

We can see that our model is working fine, giving us accurate results.

In this article we covered the key steps involved including image loading, preprocessing, edge detection and contour extraction followed by OCR for plate number recognition. By applying these techniques we can significantly enhance the accuracy of the system especially in challenging conditions. While this approach provides a solid foundation further improvements can be made using deep learning models for more complex scenarios. With these skills you can build more advanced applications in vehicle tracking, automated tolling and security systems.

You can download Source code from here.