Next-generation traffic optimization using AI, computer vision, and immersive 3D visualization
🚀 Quick Start • ✨ Features • 🎮 3D Visualization • 📖 Documentation • 🤝 Contributing
This cutting-edge AI Traffic Management System revolutionizes urban traffic control by combining advanced AI with stunning 3D visualization:
- 🤖 Reinforcement Learning (PPO) for intelligent traffic optimization
- 👁️ Computer Vision (YOLOv8) for real-time multi-camera vehicle detection
- 🚨 Emergency Vehicle Detection with automatic priority routing
- 🎮 Multiple 3D Visualization Options including Unity integration
- 🌐 SUMO Integration for realistic traffic simulation
- 📊 Real-time Web Dashboard with live analytics and controls
- 🧪 Comprehensive Testing Suite with simulated data modes
- Intelligent Traffic Optimization: PPO-based reinforcement learning for adaptive signal control
- Multi-Camera Vehicle Detection: Simultaneous processing of multiple intersection cameras
- Emergency Vehicle Priority: Real-time detection with automatic signal preemption
- Predictive Analytics: AI-driven traffic pattern analysis and optimization
- Zone-Based Detection: Configurable polygon zones for precise vehicle counting
- Integrated 3D System: Complete AI + 3D visualization in one interface
- Unity Integration: Professional game engine support with WebSocket API
- Web-Based 3D: Browser-compatible Three.js visualization with interactive controls
- Real-time Rendering: Live vehicle movement, traffic lights, and AI decisions
- Multiple Camera Angles: Interactive 3D scene exploration
- Real-time Dashboard: Live traffic statistics with animated visualizations
- RESTful API: Complete API for external integrations
- WebSocket Support: Real-time data streaming for live applications
- Mobile Responsive: Works seamlessly on desktop, tablet, and mobile
- Performance Monitoring: Live system health and performance metrics
- AI Framework: Stable Baselines3 (PPO) + Gymnasium
- Computer Vision: Ultralytics YOLOv8 + OpenCV
- 3D Graphics: Three.js + WebGL + Unity integration
- Simulation: SUMO (Simulation of Urban Mobility)
- Web Backend: Flask + Socket.IO + RESTful APIs
- Analytics: Matplotlib + Seaborn + Real-time charting
- Testing: Comprehensive test suite with simulated data modes
# Python 3.8+ required
python --version
# Install system dependencies
# Ubuntu/Debian:
sudo apt-get install sumo sumo-tools sumo-doc
# macOS:
brew install sumo
# Windows: Download from https://sumo.dlr.de/docs/Installing/# Clone the repository
git clone https://github.com/Ruchit-Gaurh/ai-traffic-management-system.git
cd ai-traffic-management
# Create virtual environment (recommended)
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt# Interactive launcher with all options
python launch.py
# Or launch specific components directly:
python launch.py --component dashboard # Web dashboard
python launch.py --component live # Live traffic analysis
python launch.py --component 3d # 3D visualization
python launch.py --component test # Test mode (no video needed)python launch.py --component 3d
# Open: http://localhost:5004Features: Complete AI + 3D visualization, interactive controls, real-time metrics
python launch.py --component unity
# API: http://localhost:5002/api/3d_data
# WebSocket: ws://localhost:5002Features: Professional Unity integration, VR/AR ready, custom game environments
python launch.py --component web3d
# Open: http://localhost:5003Features: Advanced Three.js visualization, lighting effects, interactive camera
# Terminal 1: Start dashboard
python launch.py --component dashboard
# Terminal 2: Run with simulated data
python launch.py --component test
# Open: http://localhost:5001# Terminal 1: Dashboard
python launch.py --component dashboard
# Terminal 2: Live analysis (requires video files)
python launch.py --component live
# Terminal 3: 3D visualization
python launch.py --component 3d- Dual camera processing with zone-based vehicle detection
- AI decision visualization showing KEEP/SWITCH recommendations
- Real-time queue monitoring across 4 detection zones
- Professional overlay with clean metrics display
- Immersive 3D intersection with realistic vehicle movement
- Interactive camera controls (rotate, zoom, pan)
- Real-time traffic lights synchronized with AI decisions
- Multiple visualization modes (Unity, Web3D, Integrated)
- YOLOv8-based detection of ambulances, fire trucks, police vehicles
- Automatic signal preemption for emergency vehicle priority
- Visual and audio alerts with customizable notification system
- Response time tracking and performance analytics
- Live traffic statistics with animated charts and graphs
- System health monitoring with real-time performance metrics
- Interactive controls for system configuration and testing
- Mobile-responsive design for monitoring on any device
ai-traffic-management/
├── 🚀 launch.py # Universal system launcher
├── 📋 requirements.txt # Python dependencies
├── ⚙️ config.json # System configuration
├── 🤖 project/
│ ├── 📊 models/ # Pre-trained AI models
│ │ ├── ppo_traffic_model_v*.zip # Reinforcement learning models
│ │ └── yolo_emergency_detector.pt # Emergency vehicle detector
│ ├── 🎬 videos/ # Input video files for analysis
│ ├── 📈 results/ # Performance analytics & data
│ │ ├── plot_results.py # Advanced visualization suite
│ │ ├── baseline_results.csv # Baseline performance data
│ │ └── results_v*.csv # AI performance comparisons
│ ├── 💻 src/
│ │ ├── 👁️ vision/ # Computer vision pipeline
│ │ │ ├── run_live.py # Main multi-camera analysis
│ │ │ ├── processor.py # Core vision processing
│ │ │ ├── emergency_vehicle_detection.py
│ │ │ └── new_run_live.py # Enhanced live analysis
│ │ ├── 🌐 api/ # Web services & dashboard
│ │ │ └── app.py # Flask API + WebSocket server
│ │ ├── 🎮 3D Systems/ # Multiple 3D visualization options
│ │ │ ├── simple_3d_system.py # Fast 3D visualization
│ │ │ ├── integrated_3d_system.py # Full AI + 3D integration
│ │ │ ├── unity_3d_integration.py # Unity engine support
│ │ │ └── web_3d_visualization.py # Advanced web 3D
│ │ └── 🧠 ai_core/ # AI training & optimization
│ ├── 🛣️ sumo_files/ # SUMO simulation configuration
│ └── 📊 datasets/ # Training datasets
├── 📊 tensorboard_logs/ # AI training logs & metrics
├── 🧪 test_*.py # Testing & validation scripts
└── 📖 Documentation/
├── QUICK_START.md # Getting started guide
├── 3D_SYSTEM_GUIDE.md # 3D visualization guide
└── IMPROVEMENTS_SUMMARY.md # Latest updates & fixes
Video Feeds → Computer Vision → AI Decision Engine → SUMO Simulation
↓ ↓ ↓ ↓
Zone Detection → Vehicle Counting → Traffic Optimization → 3D Visualization
↓ ↓ ↓ ↓
Emergency Alert → Priority Routing → Signal Control → Web Dashboard
# 1. Start the web dashboard (always first)
python launch.py --component dashboard
# 2. Choose your analysis mode:
# Option A: Live video analysis (requires video files)
python launch.py --component live
# Option B: Test mode (simulated data, no video needed)
python launch.py --component test
# 3. Add 3D visualization (optional)
python launch.py --component 3d
# 4. Open browser: http://localhost:5001- 's' key: Save current performance data and screenshots
- 'q' key: Quit gracefully with data export
- 'r' key: Reset analytics counters
- Mouse: Click to focus on specific detection zones
- ESC: Emergency stop (immediate shutdown)
- Automatic Detection: System continuously monitors for emergency vehicles
- Visual Alerts: Red overlay and alert messages when detected
- Audio Notifications: Optional sound alerts (configurable)
- Priority Routing: Automatic traffic signal preemption
- Response Logging: All emergency events logged for analysis
- Real-time Monitoring: Live traffic statistics and AI decisions
- Interactive Charts: Click and drag to explore historical data
- System Controls: Start/stop components remotely
- Performance Metrics: Live system health and optimization stats
- API Access: RESTful endpoints for external integrations
GET /api/stats- Current system statisticsPOST /api/update_traffic- Update traffic dataGET /api/3d_data- 3D visualization data
- Mouse Drag: Rotate camera around intersection
- Mouse Wheel: Zoom in/out
- 'R' key: Reset camera to default position
- 'P' key: Pause/resume simulation
- 'W' key: Toggle wireframe mode
- 'F' key: Toggle fullscreen (web versions)
Edit config.json to customize your video sources:
{
"video_sources": {
"intersection_1": {
"path": "project/videos/intersection1.mp4",
"description": "North-West intersection camera",
"detection_zones": [
[[874, 1086], [1443, 1035], [793, 581], [572, 590]],
[[1947, 920], [2129, 1007], [2778, 935], [2709, 856]]
]
}
}
}Getting Zone Coordinates:
- Take a screenshot of your video's first frame
- Open in image editor (Preview, Paint, GIMP)
- Note pixel coordinates at zone corners
- Define polygons clockwise from top-left
# Example: 4-point polygon for a traffic lane
ZONE_POLYGON = np.array([
[x1, y1], # Top-left corner
[x2, y2], # Top-right corner
[x3, y3], # Bottom-right corner
[x4, y4] # Bottom-left corner
], np.int32){
"models": {
"traffic_ai": {
"path": "project/models/ppo_traffic_model_v2.zip",
"type": "PPO"
},
"emergency_detector": {
"path": "project/models/yolo_emergency_detector.pt",
"type": "YOLOv8"
}
},
"detection_settings": {
"confidence_threshold": 0.5,
"decision_interval_seconds": 5,
"vehicle_classes": [2, 3, 5, 7],
"emergency_classes": ["ambulance", "fire brigade", "police"]
}
}{
"web_interface": {
"host": "0.0.0.0",
"port": 5001,
"debug": false,
"cors_enabled": true,
"auto_refresh_interval": 1000
}
}{
"display": {
"window_size": {"width": 1200, "height": 800},
"colors": {
"emergency": [0, 0, 255],
"normal": [0, 255, 0],
"zone_highlight": [0, 255, 255]
}
}
}- Traffic Flow Optimization: Up to 35% reduction in average wait times
- Detection Accuracy: 95%+ vehicle detection accuracy with YOLOv8
- Emergency Response: Sub-3-second emergency vehicle detection and signal preemption
- System Efficiency: Real-time processing of dual 1080p video streams
- AI Decision Quality: Reinforcement learning optimization with continuous improvement
- Real-time Charts: Live traffic flow, queue lengths, and AI decisions
- Historical Analysis: Performance trends over time with exportable data
- Comparative Studies: Baseline vs AI-optimized performance metrics
- Emergency Events: Detailed logging and analysis of emergency vehicle incidents
- System Health: CPU, memory, and processing performance monitoring
# Generate comprehensive performance report
python project/results/plot_results.py
# Export data for external analysis
# Results saved to: project/results/
# - baseline_results.csv (traditional timing)
# - results_v3.csv (AI-optimized performance)
# - Performance comparison charts (PNG/PDF)The system generates detailed visualizations including:
- Traffic Flow Heatmaps: Visual representation of congestion patterns
- AI Decision Timeline: Chronological view of traffic light decisions
- Queue Length Trends: Real-time and historical queue analysis
- Emergency Response Analytics: Response time distribution and patterns
- System Performance Graphs: Processing speed and resource utilization
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Video Input │───▶│ Computer Vision │───▶│ AI Decision │
│ Multi-Camera │ │ YOLOv8 + CV │ │ Engine (PPO) │
└─────────────────┘ └─────────────────┘ └─────────────────┘
│ │ │
▼ ▼ ▼
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ 3D Visualization│ │ Web Dashboard │ │ SUMO Simulation │
│ Unity/Three.js │ │ Flask + Socket │ │ Traffic Control │
└─────────────────┘ └─────────────────┘ └─────────────────┘
# Extend processor.py for new detection types
class VisionProcessor:
def detect_pedestrians(self, frame):
# Add pedestrian detection
pass
def detect_cyclists(self, frame):
# Add bicycle detection
pass# Train custom traffic optimization models
cd project/src/ai_core
python train_traffic_agent.py --config custom_config.json
# Train specialized emergency vehicle detector
python train_emergency_detector.py --dataset custom_emergency_data// Extend 3D scenes with new elements
function addCustomBuildings(scene) {
// Add custom 3D buildings
}
function addWeatherEffects(scene) {
// Add rain, fog, or other weather
}# Add new API endpoints in api/app.py
@app.route('/api/custom_analytics')
def custom_analytics():
return jsonify({"custom_data": get_custom_metrics()})# Run comprehensive test suite
python -m pytest tests/
# Test individual components
python test_model_loading.py # AI model validation
python test_dashboard_connection.py # Web interface testing
# Performance benchmarking
python benchmark_system.py --duration 300 # 5-minute benchmark# Custom PPO training configuration
from stable_baselines3 import PPO
from gymnasium import make
env = make('sumo-rl-v0', net_file='custom_intersection.net.xml')
model = PPO('MlpPolicy', env, verbose=1)
model.learn(total_timesteps=100000)
model.save('custom_traffic_model')# Custom YOLOv8 training
from ultralytics import YOLO
model = YOLO('yolov8n.pt')
model.train(
data='custom_emergency_dataset.yaml',
epochs=100,
imgsz=640,
batch=16
)# External system integration
import requests
# Get live traffic data
response = requests.get('http://localhost:5001/api/stats')
traffic_data = response.json()
# Send custom traffic updates
requests.post('http://localhost:5001/api/update_traffic',
json={'queues': [5, 3, 8, 2], 'action': 'SWITCH'})
# WebSocket real-time connection
import socketio
sio = socketio.Client()
sio.connect('http://localhost:5001')
@sio.on('traffic_update')
def on_traffic_update(data):
print(f"Live traffic: {data}")We welcome contributions from developers, researchers, and traffic management professionals!
- AI Models: Improve traffic optimization algorithms
- Computer Vision: Enhance detection accuracy and speed
- 3D Visualization: Create new visualization modes and effects
- Web Interface: Improve dashboard features and user experience
- Documentation: Help improve guides and tutorials
- Testing: Add test cases and performance benchmarks
# 1. Fork and clone the repository
git clone https://github.com/Ruchit-Gaurh/AI-Traffic-Management-System.git
cd ai-traffic-management
# 2. Create development environment
python -m venv dev-env
source dev-env/bin/activate # Windows: dev-env\Scripts\activate
# 3. Install development dependencies
pip install -r requirements.txt
pip install pytest black flake8 # Development tools
# 4. Create feature branch
git checkout -b feature/amazing-new-feature
# 5. Make your changes and test
python -m pytest tests/
python launch.py --component test # Verify system works
# 6. Commit and push
git add .
git commit -m "Add amazing new feature"
git push origin feature/amazing-new-feature
# 7. Create pull request on GitHub- Code Style: Follow PEP 8 for Python, use
blackfor formatting - Testing: Add tests for new features, ensure existing tests pass
- Documentation: Update relevant documentation and docstrings
- Performance: Ensure changes don't significantly impact system performance
- Compatibility: Test with Python 3.8+ and major operating systems
- Bug Reports: Use GitHub Issues with detailed reproduction steps
- Feature Requests: Describe the use case and expected behavior
- Performance Issues: Include system specs and performance metrics
- Quick Start Guide: Get up and running in 5 minutes
- 3D System Guide: Complete 3D visualization documentation
- Improvements Summary: Latest updates and fixes
- API Documentation: Complete API reference (coming soon)
- Smart City Traffic Management: Real-time optimization for urban intersections
- Emergency Services: Priority routing for ambulances, fire trucks, police
- Research & Education: Traffic engineering research and AI/ML education
- Simulation & Planning: Urban planning and traffic impact analysis
- Game Development: Realistic traffic simulation for games and VR/AR
This project is licensed under the MIT License - see the LICENSE file for details.
- Free for commercial use: Deploy in production environments
- Modification allowed: Customize for your specific needs
- Distribution permitted: Share and redistribute freely
- No warranty: Use at your own risk, community support available
- SUMO: Simulation of Urban Mobility - traffic simulation platform
- Ultralytics YOLOv8: State-of-the-art object detection
- Stable Baselines3: Reinforcement learning algorithms
- Three.js: 3D graphics library for web visualization
- Flask: Web framework for dashboard and APIs
- OpenAI: Advancing AI research and reinforcement learning
- Computer Vision Community: YOLO, OpenCV, and detection algorithm researchers
- Traffic Engineering: ITS (Intelligent Transportation Systems) research community
- Open Source Community: Contributors and maintainers of core dependencies
- 📖 Documentation: Check guides in this repository first
- 🐛 Issues: GitHub Issues for bugs and feature requests
- 💬 Discussions: GitHub Discussions for questions and ideas
- 📧 Email: Create an issue for direct support needs
- Example Projects: See
examples/directory for implementation samples - Video Tutorials: Coming soon - subscribe to releases for updates
- Research Papers: Links to relevant academic research in
docs/research.md - Conference Talks: Presentation materials and recordings
For enterprise deployments, custom development, or consulting:
- Custom Training: AI model training for specific intersections
- Integration Services: Connect with existing traffic management systems
- Performance Optimization: High-throughput deployments and scaling
- Technical Consulting: Traffic engineering and AI implementation guidance
Real-time Traffic Optimization • Emergency Vehicle Priority • 3D Visualization • Open Source
⭐ Star this Repository • 🔄 Fork & Contribute • 📋 Report Issues • 💡 Request Features
Made with ❤️ by the AI Traffic Management Community



