Skip to content

Debadri-das/Computer-Vision-System-for-Traffic-Monitoring

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

7 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🚦 AI Traffic Monitoring System

Python YOLOv8 Streamlit OpenCV License MacOS


A real-time Computer Vision system for intelligent traffic monitoring, vehicle detection, tracking, and congestion analysis β€” built for smart city infrastructure.


Features β€’ Demo β€’ Installation β€’ Usage β€’ Architecture β€’ Roadmap


πŸ“Έ Demo

Upload your own traffic video and watch the AI detect, track, and count vehicles in real-time.

πŸš— Vehicle detected β†’ πŸ”’ Unique ID assigned β†’ πŸ“Š Stats updated β†’ 🚦 Dashboard live

✨ Features

Feature Description Status
🎯 Real-time Detection YOLOv8 Nano for fast, accurate vehicle detection βœ… Live
πŸ”’ Multi-Object Tracking ByteTrack assigns persistent IDs across frames βœ… Live
πŸ“Š Vehicle Counting Counts vehicles crossing a virtual tripwire βœ… Live
πŸš— Vehicle Classification Detects cars, trucks, buses, motorcycles βœ… Live
πŸ“ˆ Live Dashboard Real-time Streamlit web interface with metrics βœ… Live
πŸŽ₯ Webcam Support Works with live webcam feed βœ… Live
⚑ FPS Monitoring Real-time performance tracking βœ… Live
πŸš‘ Emergency Detection Ambulance/police vehicle prioritization πŸ”„ Coming Soon
πŸ—ΊοΈ Heatmap Analysis Traffic density heatmaps per lane πŸ”„ Coming Soon
☁️ Cloud Deployment AWS/Railway deployment ready πŸ”„ Coming Soon

πŸ—οΈ Architecture

πŸ“ TrafficMonitor/
β”œβ”€β”€ πŸ“„ app.py               # Streamlit web dashboard (Frontend)
β”œβ”€β”€ πŸ“„ detector.py          # YOLOv8 detection engine (Backend)
β”œβ”€β”€ πŸ“„ requirements.txt     # Python dependencies
β”œβ”€β”€ πŸ“„ README.md            # You are here
└── πŸŽ₯ traffic.mp4          # Sample test video

Tech Stack

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                  USER BROWSER                   β”‚
β”‚              (Streamlit Dashboard)               β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                       β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚               STREAMLIT SERVER                  β”‚
β”‚                  (app.py)                       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                       β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚             DETECTION ENGINE                    β”‚
β”‚               (detector.py)                     β”‚
β”‚                                                 β”‚
β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚   β”‚ YOLOv8n  β”‚β†’ β”‚ ByteTrack β”‚β†’ β”‚  OpenCV    β”‚  β”‚
β”‚   β”‚Detection β”‚  β”‚ Tracking  β”‚  β”‚ Annotation β”‚  β”‚
β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

βš™οΈ Installation

Prerequisites

  • Python 3.9 or higher
  • MacOS / Linux / Windows
  • 4GB RAM minimum (8GB recommended)

Step 1: Clone the Repository

git clone https://github.com/YOUR_USERNAME/Computer-Vision-System-for-Traffic-MonitoringTrafficMonitor.git
cd TrafficMonitor

Step 2: Create Virtual Environment

python3 -m venv traffic_env
source traffic_env/bin/activate     # MacOS/Linux
# traffic_env\Scripts\activate      # Windows

Step 3: Install Dependencies

pip install --upgrade pip
pip install -r requirements.txt

Step 4: Download Sample Video (Optional)

curl -L -o traffic.mp4 "https://videos.pexels.com/video-files/5834623/5834623-hd_1920_1080_25fps.mp4"

πŸš€ Usage

Run the Web Dashboard

streamlit run app.py

Then open your browser at: http://localhost:8501

Run Detection Engine Directly

python3 detector.py

Dashboard Controls

  1. Upload Video β€” Upload any MP4 traffic video from the sidebar
  2. Select Source β€” Choose between video file or live webcam
  3. Click Start β€” Begin real-time AI analysis
  4. Monitor Stats β€” Watch live FPS, vehicle counts, and crossing data

πŸ“Š How It Works

1. Detection (YOLOv8)

YOLOv8 Nano scans each video frame and draws bounding boxes around detected vehicles. It classifies them into:

  • πŸš— Car
  • 🚌 Bus
  • πŸš› Truck
  • 🏍️ Motorcycle

2. Tracking (ByteTrack)

Each detected vehicle gets a unique persistent ID (#1, #2, #3...). ByteTrack is smart enough to keep the same ID even if a vehicle temporarily disappears behind another object (occlusion).

3. Counting (Virtual Tripwire)

A virtual line is drawn across the road. Every time a vehicle crosses this line, the IN or OUT counter increments depending on direction of travel.

4. Dashboard (Streamlit)

All data streams live into a professional web dashboard showing:

  • Live annotated video feed
  • Active vehicle count
  • IN / OUT crossing totals
  • Real-time FPS

πŸ“¦ Dependencies

ultralytics==8.1.0        # YOLOv8 object detection
opencv-python==4.9.0      # Video processing
streamlit==1.30.0         # Web dashboard
supervision==0.18.0       # Tracking & annotation utilities
numpy==1.26.0             # Numerical computing
pandas==2.1.0             # Data handling

πŸ—ΊοΈ Roadmap

  • Real-time vehicle detection
  • Multi-object tracking with unique IDs
  • Vehicle counting (IN/OUT)
  • Live Streamlit dashboard
  • Webcam support
  • Speed estimation (km/h)
  • Lane-specific counting
  • Emergency vehicle alerts (ambulance priority)
  • Traffic density heatmaps
  • Congestion alerts
  • REST API endpoints
  • Docker containerization
  • AWS/Railway deployment
  • Indian traffic dataset fine-tuning (rickshaws, autos)

🀝 Contributing

Contributions are welcome! Here's how:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/SpeedEstimation)
  3. Commit your changes (git commit -m 'Add speed estimation')
  4. Push to the branch (git push origin feature/SpeedEstimation)
  5. Open a Pull Request

πŸ‘€ Author

*Debadri Das
Third-year CS Student | AI/ML Enthusiast πŸ“ Kolkata, India

GitHub LinkedIn


πŸ“„ License

This project is licensed under the MIT License β€” see the LICENSE file for details.


πŸ™ Acknowledgements


⭐ If this project helped you, please give it a star!

Built with ❀️ for smart city infrastructure and Indian traffic management

About

🚦 Real-time AI Traffic Monitoring System using YOLOv8 | Vehicle Detection, Tracking & Counting

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages