Traditional traffic lights run on fixed timers β regardless of whether 1 car or 50 cars are waiting. This system uses YOLOv8 to count vehicles per lane in real time and gives the busiest lane the longest green light. Emergency vehicles get an instant override.
|
π Vehicle Detection
|
π§ Dynamic Signal Control
|
|
π¨ Emergency Override
|
π₯οΈ Simulation Mode
|
git clone https://github.com/aasimansari1/smart-traffic-system.git
cd smart-traffic-system
pip install -r requirements.txt
# Run in simulation mode (no camera needed)
python main.py
# Single image detection
python main.py --image path/to/traffic.jpg
# Video file
python main.py --mode video --source path/to/video.mp4
# Live camera
python main.py --mode camera π· Camera / Video / Simulation
β
βΌ
ββββββββββββββββββββ
β VehicleDetector β β YOLOv8 β counts cars/buses/trucks per lane
ββββββββββ¬ββββββββββ
β
βΌ
ββββββββββββββββββββ
β DensityAnalyzer β β rolling average β LOW/MEDIUM/HIGH/CRITICAL
ββββββββββ¬ββββββββββ
β
βΌ
ββββββββββββββββββββ βββββββββββββββββββββ
β SignalController β β EmergencyDetector β
β (dynamic timing) βββββββ (color analysis) β
ββββββββββ¬ββββββββββ βββββββββββββββββββββ
β
βΌ
π’ Green time: 10sβ60s (scales with density)
π¨ Emergency override: instant green
| Density | Vehicles | Green Time |
|---|---|---|
| LOW | 0 β 5 | 10 β 18s |
| MEDIUM | 6 β 15 | 19 β 32s |
| HIGH | 16 β 25 | 33 β 47s |
| CRITICAL | 25+ | 48 β 60s |
All thresholds and lane names are configurable in config/settings.py.
smart-traffic-system/
βββ config/
β βββ settings.py # All tunable params (timing, thresholds, lanes)
βββ models/
β βββ vehicle_detector.py # YOLOv8 detection pipeline
β βββ density_analyzer.py # Density classification + smoothing
β βββ signal_controller.py # Green time calculation + priority logic
β βββ emergency_detector.py # Color-based emergency detection
βββ utils/
β βββ simulator.py # Synthetic traffic frame generator
β βββ logger.py # Event logging
βββ tests/
β βββ test_density_analyzer.py
β βββ test_signal_controller.py
βββ app.py # Flask dashboard (real-time monitoring)
βββ main.py # CLI entry point
βββ yolov8n.pt # Pre-trained YOLOv8 nano weights (~6.5MB)
python tests/test_density_analyzer.py
python tests/test_signal_controller.pypython app.py
# β http://localhost:5000Real-time view of vehicle counts, density levels, and signal state per lane.
| Layer | Technology |
|---|---|
| Object Detection | YOLOv8 (Ultralytics) |
| Computer Vision | OpenCV |
| Numerical | NumPy |
| Web Dashboard | Flask |
| Pre-trained Model | yolov8n.pt (included) |
- IoT hardware integration (ESP32 / Arduino signal controllers)
- Accident detection module
- Google Maps real-time traffic data feed
- Multi-intersection coordination
- Mobile app for traffic authority alerts
git checkout -b feature/your-feature
git commit -m 'Add your feature'
git push origin feature/your-featureMIT Β© Mohd Aasim Ansari
Making roads smarter, one intersection at a time. If this interests you, please β star the repo!