Skip to main content
←All work

AI Traffic Management System

Role
Computer Vision / Backend Project
Timeline
Prototype
Status
Completed - prototype
Category
Computer Vision / AI

A real-time traffic-management prototype that uses computer vision to detect traffic density and emergency vehicles, calculate lane priority, and simulate adaptive signal timing.

This system replaces fixed-timer traffic signals with a computer-vision pipeline that inspects each lane, counts vehicles, detects emergency vehicles, and calculates which lane gets the green light and for how long. It is a prototype demonstrating adaptive signal control logic, not a system deployed in any live municipal network.

01

The problem

Fixed-cycle traffic signals cannot respond to real-time conditions - a single vehicle waiting while three queued lanes sit red, or an ambulance blocked behind a normal green cycle. This prototype demonstrates how vehicle detection and priority logic can make signal timing reactive rather than predetermined.

02

Approach

  1. Lane input

    Up to three lanes can be analysed simultaneously. Each lane accepts an uploaded image or video file (.jpg, .jpeg, .png, .mp4). The system processes them through the detection pipeline on submission.

  2. Vehicle detection

    YOLOv8 nano (yolov8n.pt via Ultralytics) runs on each frame, detecting and counting cars, trucks, buses, motorcycles, and bicycles per lane.

  3. Emergency detection

    Each frame is also sent to a specialised emergency vehicle model hosted on the Roboflow Inference API. The model identifies ambulances, fire trucks, and police vehicles with a confidence threshold of 40%.

  4. Priority and green-time calculation

    Green time is proportional to vehicle count (vehicle_count × 2 seconds), clamped between 10 and 60 seconds. Emergency vehicles in any lane trigger immediate priority for that lane. Without an emergency, the lane with the most vehicles goes first. Accident detection is noted in the repository as reserved for future expansion and is not implemented in the current version.

  5. Simulation interface

    A Flask + HTML/JavaScript/Tailwind CSS frontend renders animated traffic lights with a real-time countdown timer. Lights transition green → yellow (last 3 seconds) → red automatically. Each lane has a Force Green manual override button. A decision log records every priority calculation.

03

Stack

Backend

PythonFlask

Computer Vision

YOLOv8 (Ultralytics)Roboflow Inference APIOpenCV

Frontend

HTMLJavaScriptTailwind CSS
04

What it changes

  • Vehicle detection and counting across up to three lanes via YOLOv8.
  • Emergency vehicle detection (ambulance, fire truck, police) via Roboflow API.
  • Congestion-based adaptive green-time calculation (10-60 seconds per lane).
  • Emergency priority override logic - immediate green for the affected lane.
  • Animated traffic-light simulation with real-time countdown and decision log.
  • Manual Force Green override per lane.

This is an academic prototype. It is not deployed in or connected to any live traffic infrastructure. Accident detection is explicitly marked as a future expansion item in the repository and is not present in the current implementation.

05

About the author

I'm Aaqib Shaikh, a software engineer based in Karachi, Pakistan. I build full-stack web applications, AI systems, and machine-learning tools, from architecture to deployment, and studied Computer Science at Iqra University. The resume has the full background, more work is on the projects page, and the contact page is the way to reach me. Code lives on GitHub.