This project implements a complete pipeline for detecting vehicles, recognizing license plates, and reading Persian license plate numbers from video footage. It combines three custom-trained deep learning models for vehicle detection, license plate detection, and Persian character recognition.
Final_video.2.mp4
✅ Vehicle Detection: YOLOv8 model fine-tuned for vehicle detection
✅ License Plate Detection: Custom YOLOv8 model for license plate localization
✅ Persian OCR: CRNN model specialized for Persian license plate recognition using Tensorflow
✅ Object Tracking: ByteTrack for consistent vehicle tracking across frames
✅ Data Interpolation: Smooths bounding boxes for better visualization
Before running the Persian License Plate Recognition system, ensure you have the following installed:
- Python 3.8+ - Download from python.org
- Git - Download from git-scm.com
- CUDA-compatible GPU (optional but recommended for better performance)
git clone https://github.com/mahdimtd/persian-plate-recognition.git
cd persian-plate-recognition
# Create virtual environment
python -m venv venv
# Activate virtual environment
# On Linux/MacOS:
source venv/bin/activate
# On Windows:
venv\Scripts\activate
pip install -r requirements.txt
Download the pre-trained model weights from the repository releases/assets and place them in the weights/
directory:
weights/
├── vehicle_detection.pth
├── plate_detection.pth
└── persian_ocr.pth
python detect.py --source test_images/
# Process a single image
python detect.py --source path/to/your/image.jpg
# Process a video
python detect.py --source path/to/your/video.mp4
# Process a directory of images
python detect.py --source path/to/your/directory/
python detect.py \
--source input.jpg \
--weights weights/model.pth \
--conf-threshold 0.7 \
--output results/
Argument | Description | Default | Example |
---|---|---|---|
--source |
Input path (image/video/directory) | test_images/ |
--source video.mp4 |
--weights |
Model weights path | weights/ |
--weights custom_weights/ |
--conf-threshold |
Confidence threshold (0-1) | 0.5 |
--conf-threshold 0.7 |
--output |
Output directory | results/ |
--output my_results/ |
- Images:
.jpg
,.jpeg
,.png
,.bmp
- Videos:
.mp4
,.avi
,.mov
,.mkv
- Directory: Process all supported files in a directory
The system will generate the following outputs in the specified output directory:
- Annotated Images/Videos: Original input with bounding boxes and recognized Persian text
- Text Files: Detection results with coordinates and recognized plate numbers
- Console Output: Real-time processing information
results/
├── input_processed.jpg # Annotated image
├── input.txt # Detection results
└── processing_log.txt # Processing details
- GPU Acceleration: For faster processing, ensure you have CUDA installed and a compatible GPU
- Batch Processing: Process multiple images by pointing to a directory
- Confidence Threshold: Adjust
--conf-threshold
based on your accuracy requirements - Model Weights: Ensure you're using the latest pre-trained weights for best performance
-
Missing Dependencies: Make sure all requirements are installed
pip install -r requirements.txt
-
Model Weights Not Found: Download weights from repository releases
# Check if weights directory exists ls weights/
-
CUDA Issues: Install appropriate PyTorch version for your CUDA version
# Check CUDA version nvidia-smi
-
Permission Errors: Ensure you have write permissions to the output directory
If you encounter issues:
- Check the console output for error messages
- Verify all prerequisites are installed
- Ensure input files exist and are in supported formats
- Check that model weights are properly downloaded
- RAM: Minimum 8GB (16GB recommended)
- Storage: At least 5GB free space for models and processing
- GPU: CUDA-compatible GPU with 4GB+ VRAM (optional but recommended)
If Docker is available, you can also run the system in a containerized environment:
# Build Docker image
docker build -t persian-plate-recognition .
# Run container
docker run -v /path/to/input:/app/input -v /path/to/output:/app/output persian-plate-recognition
Note: Docker configuration may require additional setup depending on your system. ✅ Video Processing: Processes input videos and generates annotated output
✅ Persian Text Rendering: Proper bidirectional text support for Persian characters