Skip to content

About

🚦 AI traffic management system using YOLOv8 + Computer Vision | Dynamic signal control, emergency override

Topics

Resources

Contributing

Stars

3 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

CI

🚦 Smart Traffic Management System

AI-powered traffic signals that adapt in real time β€” using YOLOv8 computer vision and dynamic timing logic.

Python YOLOv8 OpenCV Flask License: MIT


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.


✨ Features

πŸš— Vehicle Detection

  • YOLOv8 detects cars, motorcycles, buses & trucks
  • Works on live camera, video file, or simulation
  • Rolling-average smoothing prevents signal thrashing

🧠 Dynamic Signal Control

  • Green time scales from 10s β†’ 60s with vehicle count
  • Busiest lane always gets priority
  • 4 density levels: LOW / MEDIUM / HIGH / CRITICAL

🚨 Emergency Override

  • Detects ambulances & fire trucks via color analysis
  • Instantly overrides signal to give emergency vehicles a clear path
  • Logs all override events

πŸ–₯️ Simulation Mode

  • Run without any camera or hardware
  • Synthetic traffic data generator included
  • Great for testing and demos

⚑ Quick Start

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

πŸ—οΈ How It Works

  πŸ“· 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

⏱️ Signal Timing Logic

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.


πŸ—‚οΈ Project Structure

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)

πŸ§ͺ Tests

python tests/test_density_analyzer.py
python tests/test_signal_controller.py

🌐 Web Dashboard

python app.py
# β†’ http://localhost:5000

Real-time view of vehicle counts, density levels, and signal state per lane.


πŸ› οΈ Tech Stack

Layer Technology
Object Detection YOLOv8 (Ultralytics)
Computer Vision OpenCV
Numerical NumPy
Web Dashboard Flask
Pre-trained Model yolov8n.pt (included)

πŸ—ΊοΈ Roadmap

  • 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

🀝 Contributing

git checkout -b feature/your-feature
git commit -m 'Add your feature'
git push origin feature/your-feature

πŸ“„ License

MIT Β© Mohd Aasim Ansari


Making roads smarter, one intersection at a time. If this interests you, please ⭐ star the repo!

About

🚦 AI traffic management system using YOLOv8 + Computer Vision | Dynamic signal control, emergency override

Topics

Resources

Contributing

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages