CoolFace
Apppublic

AhmedSouley01/traffic-monitoring

sourceHugging Faceupdated 5mo agoView on Hugging Face
0likes
App README

🚦 Traffic Monitoring System

<div align="center"> ...

Python YOLOv11 Flask ByteTrack License

Real-time road traffic object detection, tracking and counting system

Developed as part of the Computer Vision course β€” AIMS Senegal β€” April 2026

Demo β€’ Installation β€’ Usage β€’ Structure β€’ Results

</div>


πŸ“‹ Table of Contents


πŸ“Œ Description

This project implements a computer vision system dedicated to real-time road traffic monitoring. It is capable of:

  • β€”Detecting vehicles and pedestrians in traffic videos
  • β€”Tracking each object uniquely using ByteTrack
  • β€”Counting the number of unique objects passing through the scene
  • β€”Visualizing results via an interactive web interface
  • β€”Analyzing data through a statistical dashboard

This system fits into a Senegalese national context where transport authorities are looking for reliable and automated methods to understand how traffic evolves across different regions and times of day.


✨ Features

  • β€”βœ… Real-time detection with fine-tuned YOLOv11
  • β€”βœ… Persistent tracking with ByteTrack (unique ID per object)
  • β€”βœ… Unique object counting (not just per-frame counting)
  • β€”βœ… Support for local video upload and online URL
  • β€”βœ… Class selection directly from the interface
  • β€”βœ… Color-coded bounding boxes per class with ID and confidence score
  • β€”βœ… Visual alert when no object is detected in the scene
  • β€”βœ… Automatic logs in CSV and JSON format
  • β€”βœ… Interactive dashboard with charts and statistics
  • β€”βœ… CSV export of filtered detection data
  • β€”βœ… Frame-by-frame processing with timestamps

🎬 Demo

PageDescription
http://192.168.1.41:5000/Home β€” video upload and configuration
http://192.168.1.41:5000/liveReal-time detection and tracking
http://192.168.1.41:5000/dashboardLog analysis and visualization
πŸ“Έ Screenshots available in the `results/images/` folder

πŸ—οΈ Architecture

bash
Video (local or URL)
β”‚
β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Pre-processingβ”‚  OpenCV β€” frame-by-frame reading
β””β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚
β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Detection   β”‚  YOLOv11 β€” object detection
β”‚   (YOLOv11)   β”‚  conf=0.3, iou=0.45
β””β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚
β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Tracking    β”‚  ByteTrack β€” unique and persistent
β”‚  (ByteTrack)  β”‚  ID per object across frames
β””β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚
β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Counting    β”‚  ObjectCounter β€” unique object
β”‚               β”‚  counting per class
β””β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚
β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Logging     β”‚  CSV + JSON β€” timestamps,
β”‚               β”‚  classes, bbox, track IDs
β””β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚
β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Web Interfaceβ”‚  Flask β€” annotated video stream
β”‚               β”‚  + statistical dashboard
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

βš™οΈ Installation

Prerequisites

  • β€”Python 3.10+
  • β€”pip
  • β€”GPU recommended (CUDA 11.8+) β€” also works on CPU

Steps

1. Clone the repository

bash
git clone https://github.com/your-username/traffic-monitoring-project.git
cd traffic-monitoring-project

2. Create a virtual environment

bash
python -m venv venv

# Linux / macOS
source venv/bin/activate

# Windows
venv\Scripts\activate

3. Install dependencies

bash
pip install -r requirements.txt

4. Place the trained model

bash
# Copy your fine-tuned model to:
models/traffic_yolo11_best.pt
If you do not have a fine-tuned model, the pre-trained YOLOv11 model will be downloaded automatically.

5. Launch the application

bash
python app.py

6. Open in your browser

bash
http://127.0.0.1:5000
http://192.168.1.41:5000

πŸš€ Usage

Via the web interface

  1. 1.Open http://192.168.1.41:5000
  2. 2.Choose a video source:
  3. 3.Upload: select a .mp4, .avi, or .mov file
  4. 4.URL: paste a link to an online video
  5. 5.Select the classes to detect
  6. 6.Enter a scene identifier (e.g. dakar_intersection)
  7. 7.Click β–Ά Start Detection
  8. 8.View real-time results at /live
  9. 9.Click ⏹ Stop to save the logs
  10. 10.Open the Dashboard for analysis

Available arguments

ArgumentDescriptionDefault
--videoVideo path or URLrequired
--modelPath to .pt model filemodels/traffic_yolo11_best.pt
--classesClasses to detectall
--confConfidence threshold0.25
--iouIoU threshold for NMS0.45
--scene-idScene identifierscene_01
--outputOutput folderresults/
--no-displayDisable display windowFalse

πŸ“ Project Structure

bash
traffic-monitoring-project/
β”‚
β”œβ”€β”€ πŸ“‚ data/
β”‚   β”œβ”€β”€ raw_videos/          # Original raw videos
β”‚   β”œβ”€β”€ processed_videos/    # Annotated output videos
β”‚   β”œβ”€β”€ annotations/         # Annotations for fine-tuning
β”‚   └── schema.json          # Shared log schema
β”‚
β”œβ”€β”€ πŸ“‚ models/
β”‚    └── traffic_yolo11_best.pt   # Fine-tuned model
β”‚
β”œβ”€β”€ πŸ“‚ src/
β”‚   β”œβ”€β”€ detector.py          # YOLOv11 detection
β”‚   β”œβ”€β”€ tracker.py           # ByteTrack tracking
β”‚   β”œβ”€β”€ counter.py           # Unique object counting
β”‚   β”œβ”€β”€ logger.py            # Log generation
β”‚ 
β”‚   β”œβ”€β”€ templates/
β”‚   β”‚   β”œβ”€β”€ base.html
β”‚   β”‚   β”œβ”€β”€ index.html       # Home page
β”‚   β”‚   β”œβ”€β”€ live.html        # Real-time detection
β”‚   β”‚   └── dashboard.html   # Statistics
β”‚   └── static/
β”‚       β”œβ”€β”€ css/style.css
β”‚       β”œβ”€β”€ js/main.js
β”‚
β”œβ”€β”€ πŸ“„ app.py                # Flask application
β”œβ”€β”€ πŸ“„ requirements.txt      # Python dependencies
β”œβ”€β”€ πŸ“„ README.md             # This file
β”œβ”€β”€ πŸ“„ LICENSE               # MIT License
└── πŸ“„ report.pdf            # Final report

πŸ€– Model

YOLOv11 β€” Fine-tuning

ParameterValue
Base modelyolo11n.pt
Datasetbdd100k Yolo-Format Dataset / Kaggle
Epochs50
Image size640Γ—640
Batch size16
Learning rate0.001
PlatformKaggle GPU T4

Performance Metrics

MetricValue
mAP@50β€”
mAP@50-95β€”
Precisionβ€”
Recallβ€”
Metrics will be updated after final training.

🎯 Detected Classes

IDClassEmojiPriority
0person🚢⭐⭐⭐
1bicycle🚲⭐
2carπŸš—β­β­β­
3motorcycle🏍️⭐⭐⭐
5bus🚌⭐⭐
7truckπŸš›β­β­

πŸ“Š Log Format

CSV (logs/detections_*.csv)

bash
scene_id, frame, timestamp, track_id, class, confidence, x1, y1, x2, y2
scene_01, 142,  00:04.73,  7,        car,   0.912,      120,340,280,420

JSON (logs/tracking_*.json)

json
{
  "scene_id":  "scene_01",
  "frame":     142,
  "timestamp": "00:04.73",
  "detections": [
    {
      "track_id":   7,
      "class":      "car",
      "confidence": 0.912,
      "bbox":       [120, 340, 280, 420]
    }
  ]
}

πŸ“ˆ Results

Analyzed Scenes

SceneDurationSourceDetected Objects
Scene 01β€”β€”β€”
Scene 02β€”β€”β€”
Results will be filled in after testing on the selected videos.

πŸ› οΈ Dependencies

bash
flask>=3.0.0
ultralytics>=8.3.0
opencv-python>=4.8.0
numpy>=1.24.0
werkzeug>=3.0.0
PyYAML>=6.0

πŸ‘₯ Authors

NameEmail
Ahmed Souleymane Sowahmed.s.sow@aims-senegal.org
Student 2email@aims-senegal.org
Student 3email@aims-senegal.org

Supervisor: Jordan F. Masakuna β€” AIMS Senegal


πŸ“„ License

This project is licensed under the MIT License. See the LICENSE file for details.

bash
MIT License β€” Copyright (c) 2026 β€” AIMS Senegal

πŸ™ Acknowledgements

  • β€”Ultralytics for YOLOv11
  • β€”Kaggle for the datasets
  • β€”Pexels for the traffic videos
  • β€”AIMS Senegal for supervision and support

<div align="center"> <i>Built with ❀️ at AIMS Senegal β€” Computer Vision 2026</i> </div>