A Computer Vision project designed to isolate and segment the 8 characters of Iranian license plates. This project utilizes Morphological Operations and Geometric Heuristics to achieve high accuracy without the computational weight of Deep Learning models.
Character Segmentation is a critical step in Automatic License Plate Recognition (ALPR) systems. This project addresses common challenges found in Iranian plates, such as:
- Shadows & Low Contrast: uneven lighting conditions.
- Blue Strip Interference: The standard blue flag/strip on the left.
- Connected Characters: Digits merging due to blur or low resolution.
- Physical Damage: Broken characters or screw/bolt noise.
Performance:
- Accuracy: 98.68% (Tested on 70+ challenging samples).
- Speed: Real-time processing using standard CPU.
The algorithm follows a strict processing pipeline:
-
Preprocessing:
- Resizing to a fixed height (80px).
- Blue Strip Masking: Automatically whiting out the left 12% to prevent false positives from the flag.
- TopHat Transform: Enhances contrast to handle heavy shadows.
- Otsu Thresholding & Morphology: Converts to binary and cleans salt-and-pepper noise.
-
Segmentation & Heuristics:
- Contour Extraction: Identifies potential character blobs.
- Vertical Projection Profile: Detects valleys in pixel density to split characters that are "stuck" together.
- Fragment Merging: Recombines broken character parts (e.g., the letter 'گ' or '5').
- Geometric Filtering: Filters based on Aspect Ratio and Height relative to the plate.
-
Final Selection:
- Median-Y Alignment: Calculates the central line of the plate and discards noise (like frames or screws) that falls too far from the center.
- Sorting: Returns the top 8 candidates sorted from left to right.
├── inputs/ # Directory containing raw license plate images
├── output/ # Resulting images with drawn bounding boxes
├── main.py # Core algorithm implementation
├── requirements.txt # Python dependencies
├── report.pdf # Detailed project report (Persian)
└── README.md # Project documentation
- Clone the repository:
git clone https://github.com/mdvr9980/Iranian-License-Plate-Segmentation.git cd Iranian-License-Plate-Segmentation
pip install -r requirements.txtPlace your images in the inputs folder and run:
python main.pyProcessed images with visual bounding boxes will be saved in the output directory. The terminal will display the number of characters found and the accuracy score for each image.
The algorithm successfully handles various edge cases:
| Challenge | Solution |
|---|---|
| Shadows | TopHat Transformation highlights text regardless of lighting. |
| Blur/Sticking | Vertical Projection finds the optimal cut point between digits. |
| Blue Bar | Pre-masking the left margin eliminates false detections. |
| Noise | Median-Y alignment filters out screws and frame borders. |