A production-ready computer vision pipeline for matching vehicle entry/exit events using multi-engine OCR, fuzzy temporal matching, and optimized image enhancement strategies.
- Overview
- System Architecture
- Key Features
- Technical Stack
- Installation
- Usage
- Configuration
- Project Structure
- Performance
- Testing
- License
This system automatically identifies and matches vehicle entry/exit events from a dataset of 2,000+ images by:
- Extracting metadata and bounding boxes from cloud storage headers
- Detecting and cropping license plates using computer vision
- Running multi-strategy OCR with Fast-ALPR and EasyOCR fallback
- Applying fuzzy string matching with temporal logic for entry/exit pairing
Challenge Solved: Given randomized vehicle images with no explicit pairing information, the system achieves 98.15% OCR accuracy and 60.31% vehicle pairing rate through intelligent enhancement strategies and temporal filtering.
graph LR
A[Image URLs] --> B[Metadata Extractor]
B --> C[SQLite Database]
C --> D[Plate Detection YOLOv8]
D --> E[Plate Cropping]
E --> F[Multi-Engine OCR]
F --> G[Image Enhancement]
G --> H[Fast-ALPR Primary]
G --> I[EasyOCR Fallback]
H --> J[Text Normalization]
I --> J
J --> K[Fuzzy Matcher]
K --> L[Temporal Filter]
L --> M[Greedy Pairing]
M --> N[Submission Output]
style F fill:#f9f,stroke:#333,stroke-width:2px
style K fill:#bbf,stroke:#333,stroke-width:2px
style M fill:#bfb,stroke:#333,stroke-width:2px
-
Metadata Parsing π
- Async HTTP HEAD requests (30 concurrent)
- Extracts Last-Modified timestamps for temporal logic
- Parses GCS metadata headers for bbox coordinates
- 99.85% bbox extraction success rate
-
License Plate Detection πΈ
- YOLOv8 object detection for plates
- Metadata bbox fallback (99.85% coverage)
- ~115 images/second processing speed
-
Multi-Engine OCR π€
- Fast-ALPR (Primary): Specialized ALPR with ONNX runtime
- EasyOCR (Fallback): General-purpose OCR engine
- 6-Strategy Enhancement: CLAHE, sharpening, bilateral filtering, adaptive thresholding, morphological operations
- Character normalization (0/O, 1/I, 8/B, 5/S)
-
Fuzzy Temporal Matching π―
- Two-phase greedy algorithm:
- Phase 1: Exact matches (100% similarity)
- Phase 2: Fuzzy matches (75-99% similarity)
- Temporal filtering (<72 hours between entry/exit)
- Levenshtein distance with time proximity weighting
- Two-phase greedy algorithm:
Applies 6 different enhancement techniques and selects the best OCR result:
- CLAHE: Contrast-limited adaptive histogram equalization
- Sharpening: Kernel-based edge enhancement
- Bilateral: Noise reduction while preserving edges
- Adaptive Threshold: Binarization for varying lighting
- Morphological: Closing operations for character connectivity
Handles common OCR ambiguities:
character_mapping = {
"0" β "O", # Zero and letter O
"1" β "I", # One and letter I
"8" β "B", # Eight and letter B
"5" β "S", # Five and letter S
}- Timestamp-based filtering prevents incorrect matches
- Time proximity weighting: closer timestamps = higher confidence
- Configurable max time difference (default: 72 hours)
- Async retry logic for network failures
- Database transaction rollbacks
- Comprehensive logging with levels (DEBUG, INFO, WARNING, ERROR)
- Graceful degradation (EasyOCR fallback if Fast-ALPR fails)
| Category | Technology |
|---|---|
| Language | Python 3.8+ |
| Computer Vision | OpenCV 4.8+, PIL |
| Object Detection | Ultralytics YOLOv8 |
| Deep Learning | PyTorch 2.0+, TorchVision |
| OCR | Fast-ALPR (ONNX), EasyOCR |
| String Matching | FuzzyWuzzy, python-Levenshtein |
| Async I/O | aiohttp, asyncio |
| Database | SQLite3 |
| Configuration | PyYAML |
| Testing | pytest, pytest-asyncio |
- Python 3.8 or higher
- CUDA-capable GPU (optional, for faster inference)
- Clone the repository
git clone https://github.com/KPandya1903/Vehicle-Matching-System.git
cd Vehicle-Matching-System- Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies
pip install -r requirements.txtRun the complete pipeline:
python main.py --input vehicle_images_input.txt --output submission.txt- Extract Metadata Only
python main.py --phase metadata --input vehicle_images_input.txt- Run OCR Extraction
python main.py --phase ocr- Perform Matching
python main.py --phase matching- Export Submission
python main.py --phase export --output submission.txtEdit configs/config.yaml to customize:
- OCR confidence thresholds
- Matching similarity thresholds
- Maximum time difference
- Image enhancement strategies
- Logging levels
Example:
matching:
min_similarity_threshold: 75
max_time_difference_hours: 72
ocr:
fast_alpr:
confidence_threshold: 0.5Vehicle-Matching-System/
βββ src/ # Source code
β βββ data/ # Data loading & metadata extraction
β β βββ __init__.py
β β βββ metadata_extractor.py
β βββ detection/ # YOLOv8 plate detection
β β βββ __init__.py
β βββ ocr/ # Multi-engine OCR
β β βββ __init__.py
β β βββ alpr_engine.py
β βββ matching/ # Fuzzy temporal matching
β β βββ __init__.py
β β βββ vehicle_matcher.py
β βββ utils/ # Utilities
β βββ __init__.py
β βββ config_loader.py
β βββ logger.py
β βββ text_normalizer.py
βββ configs/ # Configuration files
β βββ config.yaml
βββ tests/ # Unit tests
β βββ test_text_normalizer.py
β βββ test_matching.py
βββ notebooks/ # Jupyter notebooks (EDA, visualization)
βββ assets/ # Diagrams, screenshots
βββ main.py # Main entry point
βββ requirements.txt # Python dependencies
βββ .gitignore
βββ LICENSE
βββ README.md
| Metric | Value |
|---|---|
| Total Images | 2,000 |
| Bbox Extraction | 99.85% (1,997/2,000) |
| OCR Success Rate | 98.15% (1,960/1,997) |
| OCR Confidence (Avg) | 87.8% |
| Matched Pairs | 591 |
| Match Rate | 60.31% of vehicles |
| Avg Similarity | 94.28% |
| Avg Time Diff | 6.35 hours |
| Processing Speed | ~115 images/sec (cropping) |
- Fast-ALPR (Optimized): 96.67% (1,896 plates)
- EasyOCR (Fallback): 3.27% (64 plates)
- Exact Matches: 368 pairs (100% similarity)
- Fuzzy Matches: 223 pairs (75-99% similarity)
Run unit tests:
pytest tests/ -vRun with coverage:
pytest tests/ --cov=src --cov-report=htmlThis project is licensed under the MIT License - see the LICENSE file for details.
- Fast-ALPR: Open-source ALPR library (GitHub)
- Ultralytics YOLOv8: State-of-the-art object detection
- EasyOCR: Robust general-purpose OCR engine
Built with β€οΈ for computer vision and intelligent systems