A comprehensive, intelligent traffic control system that uses computer vision and machine learning to optimize traffic flow, reduce congestion, and improve urban transportation.
The Traffic Control System is a modular solution designed to manage traffic lights efficiently by analyzing real-time traffic conditions. It employs computer vision for vehicle detection, machine learning for traffic prediction, and inter-traffic light communication for coordinated traffic management.
- Vehicle Detection: Uses computer vision to detect and count vehicles in real-time
- Traffic Density Analysis: Calculates traffic density and congestion levels
- Dynamic Traffic Light Control: Adjusts signal timing based on current traffic conditions
- Green Wave Coordination: Creates coordinated "green waves" for improved traffic flow
- Emergency Vehicle Priority: Automatically creates green corridors for emergency vehicles
- Public Transport Integration: Gives buses and trams priority at intersections
- Pedestrian Safety: Responsive to pedestrian crossing requests
- Weather Integration: Adjusts traffic patterns based on weather conditions
- Machine Learning Prediction: Predicts traffic patterns using historical data
- Interactive Dashboard: Web-based visualization of traffic data and statistics
- Simulation Mode: Test the system without physical hardware
┌────────────────────────────────────────────────────────────────────┐
│ System Integrator │
└───────────────────────────┬────────────────────────────────────────┘
│
▼
┌────────────────────────────────────────────────────────────────────┐
│ Event Manager │
└───────┬─────────┬──────────┬─────────┬───────────┬─────────┬───────┘
│ │ │ │ │ │
▼ ▼ ▼ ▼ ▼ ▼
┌──────────┐ ┌─────────┐ ┌────────┐ ┌────────┐ ┌────────┐ ┌────────┐
│Green Wave│ │Emergency│ │ Public │ │Pedestr.│ │Weather │ │ V2I │
│Controller│ │ Control │ │Transp. │ │Control │ │Control │ │Control │
└──────────┘ └─────────┘ └────────┘ └────────┘ └────────┘ └────────┘
│ │ │ │ │ │
└─────────┴──────────┴─────────┴───────────┴─────────┘
│
▼
┌──────────┐ ┌─────────┐ ┌────────────┐ ┌────────────┐ ┌───────────┐
│ ML Pred. │ │Analytics│ │ Dashboard │ │Event Logger│ │Simulation │
│Controller│ │ Control │ │ Controller │ │ Controller │ │Controller │
└──────────┘ └─────────┘ └────────────┘ └────────────┘ └───────────┘
- Python 3.8 or higher
- Git (optional, for cloning the repository)
git clone https://github.com/ErfanZohrabi/traffic-control-system.git
cd traffic-control-system# Linux/macOS
python -m venv venv
source venv/bin/activate
# Windows
python -m venv venv
.\venv\Scripts\activatepip install -r requirements.txt
pip install -e .We've created a script that automatically fixes common issues:
python fix_traffic_system.pyWe've created a simplified demo that works without TensorFlow or OpenCV:
python simple_demo.pyThis will:
- Start the traffic control system
- Simulate traffic patterns for 30 seconds
- Display events in the console
The dashboard provides a visual interface to monitor the traffic system:
python test_dashboard.pyThis will:
- Start the traffic control system
- Launch a web dashboard at http://localhost:8080
- Simulate traffic patterns for demonstration
For a comprehensive demo of all traffic control features:
python demo.pyFor a quick test of the core functionality:
python test_minimal.pyTo test the RESTful API for external system integration:
python test_api.pyFor Windows users, we've created helper scripts:
# Using PowerShell
.\run_traffic.ps1
# Or using batch files
.\run_dashboard.bat
.\run_demo.batSee WINDOWS_SETUP.md for detailed Windows setup instructions.
| Module | Description |
|---|---|
| Green Wave | Creates coordinated traffic light timing for smooth traffic flow |
| Emergency | Prioritizes emergency vehicles through intersections |
| Public Transport | Gives priority to buses, trams, and other public transit |
| Pedestrian | Manages pedestrian crossings and safety features |
| Weather | Integrates weather data to adjust traffic patterns |
| Analytics | Collects and analyzes traffic data for insights |
| Mobile App | Provides integration with mobile applications |
| ML Prediction | Uses machine learning to predict traffic patterns |
| Dashboard | Web-based visualization and control interface |
| V2I | Vehicle-to-Infrastructure communication |
| Event Logger | Records and analyzes system events |
| Simulation | Simulates traffic patterns for testing |
The system can be configured using JSON or YAML files:
# Export default configuration
python main.py --export-config config.yaml
# Run with custom configuration
python main.py --config config.yaml- ModuleNotFoundError: Make sure you've installed the package in development mode with
pip install -e . - Address already in use: Another process is using port 8080, modify the dashboard port or close the other application
- TensorFlow Import Error: Make sure TensorFlow is installed with
pip install tensorflow - System exits immediately: Check logs in the
logs/directory for error messages
For Windows-specific issues, see WINDOWS_SETUP.md.
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
For any inquiries, please contact erfanzohrabi.ez@gmail.com.
Erfan Zohrabi
- GitHub: ErfanZohrabi
- LinkedIn: in/erfan-zohrabi