A complete Automatic License Plate Recognition (ALPR) system built from scratch. This project serves as a Proof of Concept (PoC) to demonstrate the integration of classic computer vision techniques for image segmentation with a custom-trained Support Vector Machine (SVM) model for Optical Character Recognition (OCR).
Unlike out-of-the-box OCR APIs, this project involves manually processing the image, extracting the features, and training a custom Machine Learning classifier.
Note: This PoC is designed and calibrated for controlled environments (ideal lighting, frontal perspective). It showcases fundamental algorithm design and logic before scaling to deep learning architectures.
The system operates in three main stages:
-
Plate Detection (Computer Vision):
- The raw image is converted to grayscale.
- Otsu's Thresholding is applied for adaptive binarization based on the image's histogram.
- Connected Component Analysis (
skimage.measure) is used to label regions. - Heuristics (height/width ratios and bounding box boundaries) filter out noise to isolate the vehicle's license plate.
-
Character Segmentation:
- The cropped license plate undergoes a secondary thresholding process to isolate individual dark characters against the light background.
- Bounding boxes are drawn around each individual letter and number.
-
Optical Character Recognition (Machine Learning):
- A dataset of alphanumeric characters is processed and resized to a strict
20x20pixel grid. - The matrices are flattened into 1D arrays to extract numerical features.
- A Support Vector Machine (SVM) classifier is trained on these features to predict the characters.
- A dataset of alphanumeric characters is processed and resized to a strict
- Language: Python
- Computer Vision:
scikit-image - Machine Learning:
scikit-learn - Data Visualization:
matplotlib
├── images/ # Sample images for testing
├── models/
│ └── svc/ # Contains the trained SVM model (.pkl)
├── train20X20/ # Dataset used to train the OCR model
├── characterSegmentation.py # Isolates characters from the cropped plate
├── gray.py # Image preprocessing functions
├── main.py # Entry point for the ALPR pipeline
├── position.py # Handles bounding box coordinates
├── recognition.py # OCR script using the trained SVM
├── requirements.txt # Project dependencies
└── README.md
Since this pipeline relies on classic computer vision (global binarization and fixed proportion heuristics), it is highly sensitive to variations in lighting, shadows, and extreme angles.
Future improvements:
-Replace the heuristic-based plate localization with a Deep Learning object detection model (e.g., YOLOv8 or Haar Cascades) for robust detection in uncontrolled environments.
-Implement adaptive local thresholding to better handle shadows and reflections on the bumper.
-Expand the 20x20 dataset with augmented images (rotations, blur) to improve the SVM's OCR accuracy.