TrafficVision is an AI-powered traffic violation detection system inspired by Saher. It uses a sophisticated multi-stage YOLO pipeline to automatically detect seatbelt and mobile phone violations, combined with license plate detection and OCR for violator identification.
-
Multi-Stage Detection Pipeline
- Vehicle detection (cars, buses, trucks)
- Violation detection (seatbelt, mobile phone usage)
- License plate detection
- OCR text extraction from license plates
-
Multiple Violation Types
- Person without seatbelt detection
- Mobile phone usage detection
- Helmet violations (for motorcycles)
-
Flexible Usage
- Command-line interface (CLI) for batch processing
- Web interface powered by Gradio
- Installable via
uvxfor one-off usage
-
Output Options
- Save violation images with bounding boxes
- Save license plate images
- JSON output with violation details
- OCR text extraction
Process a single image:
uvx git+https://github.com/AFAskar/trafficvision path/to/image.jpgLaunch the web interface:
uvx --from git+https://github.com/AFAskar/trafficvision trafficvision-webuv tool install git+https://github.com/AFAskar/trafficvisiongit clone https://github.com/AFAskar/trafficvision.git
cd trafficvision
uv pip install -e .Basic usage:
trafficvision path/to/image.jpgProcess a directory of images:
trafficvision path/to/images/Save all outputs (violation images and license plates):
trafficvision path/to/image.jpg --saveSave only license plate images:
trafficvision path/to/image.jpg --save-platesSave only violation images with bounding boxes:
trafficvision path/to/image.jpg --save-violationsLaunch the Gradio web interface:
trafficvision-webThen open your browser to the provided URL (typically http://127.0.0.1:7860)
from pathlib import Path
from trafficvision.pipeline import run_pipeline, get_violation_type
# Run the detection pipeline
images = [Path("path/to/image.jpg")]
violation_results, plate_results, ocr_results = run_pipeline(images)
# Get violation types
for violation in violation_results:
violation_types = get_violation_type(violation.boxes)
print(f"Detected violations: {violation_types}")
# Get OCR text from license plates
for ocr_text in ocr_results:
print(f"License plate text: {ocr_text}")TrafficVision uses a multi-stage detection pipeline:
- Vehicle Detection: Uses YOLOv11n to detect vehicles (cars, buses, trucks) in the input image
- Violation Detection: Analyzes detected vehicles for traffic violations using a custom-trained YOLO model
- License Plate Detection: Locates license plates on vehicles with detected violations using a fine-tuned YOLO model
- OCR Processing: Extracts text from license plates using Tesseract OCR
The system uses three pre-trained YOLO models:
yolo11n.pt- YOLOv11 Nano for vehicle detectionseatbelt.pt- Custom-trained model for violation detectionlicense-plate-finetune-v1s.pt- Fine-tuned model for license plate detection
- Python 3.13+
- PyTorch
- Ultralytics YOLO
- Tesseract OCR
- Gradio (for web interface)
- Other dependencies listed in
pyproject.toml
The seatbelt detection model was trained on the Seat Belt Detection dataset from Roboflow (CC BY 4.0 license).
Violation 1:
- Violation Types: ['person-noseatbelt', 'mobile']
- OCR Text: ABC 1234
The system can generate JSON output with the following structure:
[
{
"ABC 1234": {
"violation_type": ["person-noseatbelt"],
"violation_bbox": [...],
"violation_image": "violation_0.png",
"license_plate": "plate_0.png"
}
}
]Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the AGPLv3 License - see the LICENSE file for details.
- Inspired by the Saher traffic violation detection system
- Built with Ultralytics YOLO
- Dataset from Roboflow Universe
- License Plate Detection Model from morsetechlab
- OCR powered by Tesseract
AFAskar
Current version: 0.1.13