This repository contains a complete, end-to-end Python application for detecting and recognizing vehicle license plates from images. The system is built using a combination of deep learning for object detection and a powerful OCR engine for character recognition.
(Note: You should replace the image above with a screenshot of your final output. I suggest creating a demo folder and placing the image there.)
- License Plate Detection: Accurately localizes license plates in images using a custom-trained YOLOv8 model.
- Character Segmentation: Implements a robust computer vision pipeline with OpenCV to isolate individual characters from the detected plate, even with varying image sizes.
- Character Recognition: Utilizes the powerful EasyOCR engine to achieve high accuracy in reading the segmented characters.
- Batch Processing: Automatically finds and processes all images in a designated
testfolder. - Post-Processing: Includes logic to clean the final output and remove non-alphanumeric characters for a more accurate reading.
The system operates on a three-phase pipeline:
-
Phase 1: Localization
- A custom-trained YOLOv8n object detection model (
best.pt) is used to find the bounding box of the license plate in the input image. - This model was fine-tuned on a dataset of Indian license plates, making it specific to this task.
- A custom-trained YOLOv8n object detection model (
-
Phase 2: Segmentation
- The cropped plate image from Phase 1 is passed to a custom segmentation script.
- The script uses OpenCV for preprocessing, including resizing to a standard height (for robustness), grayscale conversion, and Otsu's binarization.
- Contour detection is then used to find all potential characters, which are filtered based on size and aspect ratio to isolate only the valid ones.
-
Phase 3: Recognition
- The segmented character data is passed to the EasyOCR engine.
- EasyOCR, a pre-trained deep learning model, reads the text from the plate.
- The raw output is then cleaned using a post-processing filter to yield the final license plate number.
- Language: Python 3.11+
- Core Libraries:
- Ultralytics (YOLOv8): For object detection.
- EasyOCR: For character recognition.
- OpenCV (cv2): For all image processing and segmentation tasks.
- NumPy: For numerical operations.
- PyTorch: As the backend for both YOLOv8 and EasyOCR.
Follow these steps to set up and run the project locally.
1. Prerequisites:
- Python 3.11 or higher.
gitfor cloning the repository.
2. Clone the Repository:
git clone [Link to your GitHub Repo]
cd ALPR_Project