An end-to-end deep learning pipeline for detecting and recognizing Tunisian license plates in images. Built with state-of-the-art object detection and OCR models, featuring an interactive web interface.
Demo • Features • Quick Start • Results • Usage
Cascade R-CNN detects all vehicles in the image with bounding boxes
Faster R-CNN localizes license plates on detected vehicles
Advanced image preprocessing: denoising, upscaling (4x-6x), CLAHE, binarization
CRNN model reads characters and formats plates in Tunisian standard (Arabic + digits)
- Stage 1: Vehicle Detection using Cascade R-CNN
- Stage 2: License Plate Detection using Faster R-CNN
- Stage 3: Adaptive Image Enhancement (4 methods)
- Stage 4: OCR Recognition using CRNN with CTC Loss
- 4 Enhancement Methods: Original, Light, Full (recommended), Aggressive
- Techniques:
- Denoising (fastNlMeans)
- Super-resolution upscaling (4x-6x)
- Contrast enhancement (CLAHE)
- Gamma correction
- Bilateral filtering
- Adaptive binarization
- Morphological operations
- Built with Streamlit for easy deployment
- Real-time processing with live visualization
- Adjustable confidence thresholds
- Multiple enhancement method selection
- Downloadable results
- Recognizes both standard and private plates
- Automatic formatting with Arabic text (تونس / نت)
- Proper number grouping and centering
- Format:
XXX تونس XXXXorXXXXXX نت
- Python 3.8+
- CUDA-capable GPU (optional, for faster processing)
- Git
- Clone the repository
git clone https://github.com/Malek-logh/AutoPlateTN.git
cd AutoPlateTN- Clone Detectron2 (no pip install needed)
git clone https://github.com/facebookresearch/detectron2.git- Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
pip install opencv-python numpy pandas streamlit pillow tqdm
pip install fvcore- Download pre-trained models
- Place your trained models in
models/detection/andmodels/ocr/ - Required files:
cascade_best.pth(vehicle detection)fasterrcnn_tunisia_plates.pth(plate detection)best_crnn_model.pth(OCR)- Optional:
best_crnn_light.pth,best_crnn_full.pth,best_crnn_aggressive.pth
- Place your trained models in
streamlit run app.pyThen open your browser at http://localhost:8501
# Step 1: Detect vehicles
python vehicle_detection_inference.py
# Step 2: Detect plates
python platedetectortest.py
# Step 3: Enhance plates
python src/preprocessing/image_enhancing.py
# Step 4: Run OCR
python test_crnn_model.py- Launch the app:
streamlit run app.py - Upload an image containing vehicles
- Adjust confidence thresholds if needed
- Select enhancement method (Full recommended)
- Click "Start Processing"
- View results with formatted plate numbers
If you want to train your own models:
- Dataset: https://universe.roboflow.com/rjacaac1/ua-detrac-dataset-10k/dataset/2
- Framework: Detectron2
- Architecture: Cascade Mask R-CNN (R-50-FPN)
- Classes: 4
- Dataset: https://datasetninja.com/tunisian-licensed-plates
- Framework: PyTorch + torchvision
- Architecture: Faster R-CNN (ResNet-50-FPN)
- Classes: 2 (background + license plate)
- Dataset: https://zindi.africa/competitions/ai-hack-tunisia-2-computer-vision-challenge-2/data
- Framework: PyTorch
- Architecture: CRNN (CNN + BiLSTM)
- Loss: CTC (Connectionist Temporal Classification)
- Characters:
0123456789TN(digits + Tunisia marker)
Star this repository if you find it helpful!