AI TRAFFIC MGMT
1 / 14
←
→
FINAL YEAR PROJECT — COMPUTER ENGINEERING
AI BASED TRAFFIC MANAGEMENT SYSTEM
Real-Time YOLOv8 Detection • Adaptive Signal Control • Smart City Dashboard
Python Flask
YOLOv8 Nano
React + TypeScript
PostgreSQL
OpenCV
02
WHY TRAFFIC SYSTEMS ARE FAILING
⏱
FIXED SIGNAL TIMING
Signals run on preset schedules regardless of actual traffic density or congestion
👁
NO REAL-TIME VISIBILITY
Manual monitoring misses sudden congestion events and peak-hour surges
⚠
ZERO ADAPTIVE RESPONSE
System cannot react to accidents, emergencies, or peak-hour congestion
🗄
INSUFFICIENT DATA
No historical storage means no learning, no optimization, no planning
💡
"Urban traffic congestion costs cities
billions
in lost productivity annually — yet most signals still run on 1970s logic"
03
WHAT WE BUILT
DETECTION & CONTROL PIPELINE
CAMERA
FEED
→
YOLOv8
DETECTION
→
VEHICLE
TRACKING
→
LANE LOAD
CALC
→
ADAPTIVE
SIGNAL
→
SMART
DASHBOARD
🤖
YOLOv8 NANO
Real-time inference at high FPS
Conf: 0.25 | IoU: 0.45
🚦
4-WAY ADAPTIVE CONTROL
Dynamic green phase durations
15 seconds → 60 seconds
📊
FULL-STACK DASHBOARD
React + Flask + PostgreSQL
Live monitoring & analytics
04
TECHNOLOGY STACK
⚙ BACKEND
Python Flask
REST API gateway
YOLOv8 Nano
Object detection engine
OpenCV
Video capture & frame processing
PostgreSQL
Historical data storage
Centroid Tracker
Multi-vehicle tracking
🖥 FRONTEND
React 18 + TypeScript
Dashboard UI framework
Tailwind CSS + shadcn/ui
Component system
Recharts
Analytics graphs
React Leaflet
Traffic map visualization
Three.js
3D animated background effects
Model: yolov8n.pt | Confidence threshold: 0.25 | IoU: 0.45 | Backend: localhost:5000 | Frontend: localhost:5173
05
4-LAYER ARCHITECTURE
TIER 1 — PRESENTATION LAYER
React + TypeScript Dashboard
Vehicle Detection
Signal Control
Analytics
Alerts
Settings
▼
TIER 2 — APPLICATION LAYER
Python Flask REST API
/api/detect
/api/signal
/api/alerts
/api/analytics
/api/roi-config
▼
TIER 3 — PROCESSING LAYER (CORE ENGINE)
Frame Acq.
→
YOLOv8
→
Tracking
→
Lane Load
→
Signal Phase
→
Alert Eval
→
DB Store
▼
TIER 4 — DATA LAYER
PostgreSQL — historical_traffic
OpenWeatherMap API
SMTP Server
roi_config.json
06
REAL-TIME DETECTION PIPELINE
LIVE DETECTION FEED — ACTIVE
CAR #12 — 42 km/h
TRUCK #7 — 28 km/h
BUS #3 — 35 km/h
NORTH ROI
SOUTH ROI
CARS: 183
TRUCKS: 37
BUSES: 84
TOTAL: 304
304
VEHICLES DETECTED
183 cars | 37 trucks | 84 buses
54–89%
AI CONFIDENCE RANGE
Per detection, per frame
4
CLASSES DETECTED
Car · Truck · Bus · Bike
Output: [x1, y1, x2, y2, conf, class_id]
conf=0.25 | IoU=0.45
Speed = Δcentroid ÷ Δt × px_ratio × 3.6
07
ADAPTIVE SIGNAL CONTROLLER
ADAPTIVE RUNNING
NORTH
45s
65%
SOUTH
—
40%
EAST
—
20%
WEST
—
15%
NS GREEN → NS YELLOW → EW GREEN → EW YELLOW → ↺
LANE LOAD %
GREEN DURATION
< 20%
15 seconds
20 – 40%
30 seconds
40 – 70%
45 seconds
≥ 70%
60 seconds
LANE LOAD FORMULA
load = (count × 0.5) + (density × 30) + ((1 − speed_norm) × 20)
08
VIRTUAL LANE DETECTION (ROI)
ROI CONFIGURATION EDITOR
NORTH (4 pts)
SOUTH (4 pts)
EAST (4 pts)
WEST (4 pts)
N
S
E
W
Edit ROI
Save ROI
Reload
01
Operator defines
4-point polygons
per lane on live video
02
Coordinates stored as
normalized values (0.0–1.0)
in roi_config.json
03
Ray-casting algorithm
assigns each vehicle centroid to a lane
04
Priority order:
NORTH → SOUTH → WEST → EAST
(prevents double-counting)
05
Lane loads computed and sent to signal controller
every frame
Algorithm: _point_in_poly() — ray-casting
Storage: roi_config.json (normalized coords)
09
REAL-TIME ANALYTICS
Traffic Flow Analytics — Last 24 Hours
00:00
12:00
24:00
Historical Comparison — Mon vs Tue
● Monday
● Tuesday
Highway
78%
Arterial
71%
Local
82%
4.8 min
AVG WAIT TIME ESTIMATED
/api/analytics/weekly
/api/analytics/compare
/api/minute-vehicle-count
STORAGE
Every 60s
QUERIES
Hourly + Weekly
10
ALERT & NOTIFICATION SYSTEM
0 HIGH
1 MEDIUM
0 LOW
0 RESOLVED
MEDIUM
02:24:44
Congestion Detected
Moderate traffic detected at intersection
Dashboard alert only — no email dispatched
RESOLVED
01:15:22
Congestion Cleared
Traffic returned to NORMAL level
🔴
HIGH PRIORITY
Congestion = SEVERE → Email dispatched via SMTP instantly
🟡
MEDIUM PRIORITY
Congestion = MODERATE → Dashboard alert only, no email
🟢
AUTO-RESOLVED
Congestion clears → Alert resolves, email tracker reset
⚡ Duplicate email prevention — each alert ID triggers max 1 email per activation cycle
11
DATABASE SCHEMA
TABLE: historical_traffic
COLUMN
TYPE
CONSTRAINT
DESCRIPTION
id
SERIAL
PRIMARY KEY
Auto-increment unique identifier
recorded_at
TIMESTAMP
NOT NULL, INDEXED
Snapshot timestamp (fast queries)
vehicle_count
INTEGER
DEFAULT 0
Total tracked vehicles
average_speed
FLOAT
DEFAULT 0.0
Average speed in km/h
congestion_level
VARCHAR(50)
—
NORMAL / MODERATE / SEVERE
WEEKLY TRENDS QUERY
SELECT DATE(recorded_at), SUM(vehicle_count)
FROM historical_traffic
GROUP BY DATE ORDER BY date
HOURLY COMPARISON QUERY
SELECT EXTRACT(HOUR FROM recorded_at),
AVG(average_speed) FROM historical_traffic
WHERE DATE = %s GROUP BY hour
Single flat schema — optimized for fast inserts and aggregation queries | Snapshot every 60 seconds
12
TESTING & VALIDATION — 35 TEST CASES
🔍
10/10
PASS
DETECTION & TRACKING
YOLOv8 reliable in daylight, speed within 10% error
🚦
8/8
PASS
SIGNAL CONTROL
Adaptive timing, min enforcement, pause/resume validated
🔔
7/7
PASS
ALERTS & EMAIL
Correct trigger/resolve, duplicate prevention confirmed
🗄
6/6
PASS
DATABASE
Idempotent schema, 60s inserts, resilient to DB downtime
🌐
10/10
PASS
API ENDPOINTS
All HTTP codes correct, CORS validated, input sanitized
100%
OVERALL PASS RATE — 35/35 TEST CASES
Testing conducted using pre-recorded traffic videos, mock data injection, and live dashboard monitoring
13
WHERE WE GO NEXT
⚠ CURRENT LIMITATIONS
Single intersection only — no multi-camera support yet
Signal control is simulated — no real hardware integration
No user authentication or role-based access control
Emergency vehicle detection removed from current scope
Speed estimation uses simplified pixel-to-meter conversion
Some analytics data simulated for demonstration
🚀 FUTURE ENHANCEMENTS
Custom AI model trained on Indian traffic conditions
Multi-intersection + multi-camera architecture
Deep SORT advanced tracking algorithm
Reinforcement learning signal optimization
Docker + cloud deployment (AWS / GCP)
Mobile app for remote monitoring
V2X (Vehicle-to-Everything) integration
Environmental emission monitoring
14
WHAT WE ACHIEVED
🤖
YOLOv8 DETECTION
Real-time vehicle detection & classification across 4 classes
🚦
ADAPTIVE SIGNALS
4-way adaptive control — 15s to 60s dynamic green phases
📊
FULL-STACK DASHBOARD
React + Flask live monitoring, analytics & visualization
🔔
ALERT SYSTEM
Automated alert generation & SMTP email notifications
🗄
HISTORICAL ANALYTICS
PostgreSQL storage with hourly & weekly trend queries
✅
35/35 TESTS PASSED
100% pass rate across all functional test categories
"A scalable, AI-driven traffic management prototype — ready for real-world smart city deployment."
Stack: Python • Flask • YOLOv8 • OpenCV • React • TypeScript • PostgreSQL
← → Arrow Keys to Navigate | F for Fullscreen