Skip to content

sksalman0/Dynamic_Traffic_System

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

🚦 Dynamic Traffic Management System

Real-Time Vehicle Detection & Fair Signal Optimization

📌 Project Overview

This project simulates a 4-way traffic intersection powered by real-time vehicle detection using a pre-trained YOLO model.

Instead of using fixed signal timers, the system dynamically adjusts green and red light durations based on vehicle counts detected from real traffic video feeds.

The system integrates:

  • Computer Vision (YOLO + OpenCV)
  • Simulation Engine (Pygame)
  • GUI-based File Selection (Tkinter)
  • Multi-threaded Processing
  • Custom Traffic Time Allocation Algorithm

🎯 Objective

Traditional traffic systems:

  • Use fixed signal timings
  • Cause unfair red-light wait times
  • Waste green time when traffic is low

This project aims to:

  • Detect vehicles from 4 real traffic videos
  • Count vehicles per lane
  • Simulate a 4-sided intersection
  • Dynamically calculate signal timing
  • Maintain fairness in red-light distribution
  • Prevent unnecessary signal time waste

🧠 System Architecture

1️⃣ Vehicle Detection (Computer Vision)

Libraries Used:

  • cv2 (OpenCV)
  • YOLO (Pre-trained object detection model)
  • numpy

Each of the four traffic videos is processed using YOLO to:

  • Detect vehicles (cars, buses, trucks, bikes)
  • Draw bounding boxes
  • Count vehicles per direction

The detected vehicles are not randomly generated. They are derived from actual detection results.


2️⃣ Simulation Engine (Pygame)

Libraries Used:

  • pygame
  • random
  • time

A visual 4-way traffic junction is simulated using Pygame.

Features:

  • Four traffic sides
  • Virtual vehicles spawned based on detection count
  • Real-time signal switching
  • Dynamic timer display

The simulation visually represents traffic conditions detected from the videos.


3️⃣ File Selection Interface (Tkinter)

Libraries Used:

  • tkinter
  • filedialog

Tkinter is used to:

  • Select four traffic video files
  • Allow flexible input instead of hardcoded paths

This makes the system interactive and user-driven.


4️⃣ Multi-threaded Processing

Libraries Used:

  • threading

Threading ensures:

  • Video processing runs in parallel
  • Simulation remains responsive
  • Detection and rendering occur simultaneously

This improves system efficiency and realism.


⚙️ Dynamic Time Allocation Algorithm

This is the core innovation of the project.

Unlike traditional traffic lights:

  • Signals are not fixed duration
  • Green time is not random
  • Red time is not unfairly long

Logic:

  • Higher vehicle count → Longer green duration
  • Lower vehicle count → Shorter green duration
  • Red time balanced across all sides
  • Continuous recalculation based on updated counts
  • No direction is starved

This ensures:

  • Fair signal distribution
  • Efficient vehicle movement
  • Reduced idle green time

🔄 System Workflow

  1. User selects 4 traffic videos via Tkinter
  2. YOLO detects and counts vehicles using OpenCV
  3. Vehicle counts are fed into simulation
  4. Time allocation algorithm calculates signal duration
  5. Pygame updates traffic lights dynamically
  6. Process repeats continuously

🛠 Tech Stack

  • Python
  • OpenCV (cv2)
  • YOLO (Pre-trained object detection model)
  • Pygame
  • Tkinter
  • NumPy
  • Threading

📊 Key Concepts Demonstrated

  • Real-time object detection
  • Vehicle counting using bounding boxes
  • Multi-threaded system design
  • Simulation modeling
  • Fairness-aware algorithm design
  • Dynamic resource allocation
  • Integration of multiple libraries into one system

🚀 Why This Project Matters

This project combines:

  • Computer Vision
  • Algorithm Design
  • Simulation Systems
  • Real-Time Processing

It demonstrates the ability to:

  • Integrate ML models into working systems
  • Translate detection output into intelligent decision logic
  • Design fairness-based traffic optimization
  • Build simulation-based prototypes for smart city systems

⚠️ Note

This is a simulation-based smart traffic system.

Although real traffic videos are used for vehicle detection, the intersection itself is simulated using Pygame.

The goal was to build a realistic prototype of a dynamic traffic control system.


🔮 Future Improvements

  • Live CCTV feed integration
  • Emergency vehicle prioritization
  • Reinforcement learning-based optimization
  • Add metrics (average wait time, throughput efficiency)
  • Deploy as a real-time dashboard

👤 Author

SK Salman
Machine Learning & Computer Vision Enthusiast

About

Real-time dynamic traffic signal simulation using YOLO-based vehicle detection, Pygame visualization, and fairness-aware signal timing algorithm.

Topics

Resources

Stars

Watchers

Forks

Contributors

Languages