UrbanFlow is a cutting-edge, AI-driven computer vision system designed for intelligent traffic monitoring and adaptive signal control. Developed as a BTech Major Project, it offers a comprehensive, standalone pipeline for real-time analysis of traffic flow, detection of violations, and dynamic adjustment of traffic signals. Optimized for CPU usage, UrbanFlow makes advanced AI traffic management accessible for academic research and practical deployment in smart city initiatives.
UrbanFlow integrates multiple advanced computer vision and AI techniques to provide a holistic traffic management solution:
-
Utilizes YOLOv8/YOLOv11 Nano models for high-speed and accurate detection of various vehicle types.
-
Detects and classifies Cars, Buses, Trucks, and Motorcycles with bounding boxes and confidence scores.
-
Supports custom-trained YOLO models for specialized detection needs.
-
Provides accurate, real-time counts of vehicles per frame.
-
Offers class-wise breakdown, allowing for granular insights into traffic composition.
-
Overlays counts directly onto the processed video feed for immediate visualization.
-
Categorizes traffic into LOW, MEDIUM, and HIGH density levels based on real-time vehicle counts.
-
This estimation forms the backbone of the adaptive signal control system.
| Density Level | Vehicle Count Threshold | Signal Duration (Green Light) |
|---|---|---|
| LOW | < 5 vehicles | 15 seconds |
| MEDIUM | 5 - 25 vehicles | 30 seconds |
| HIGH | > 25 vehicles | 45 seconds |
-
Implements a rule-based system that dynamically adjusts traffic light timings based on detected traffic density.
-
Features a real-time countdown timer displayed on the video output.
-
Logs signal state changes to the console, providing transparency and auditability.
-
Employs OpenCV's Canny Edge Detection and Hough Transform to accurately identify and draw lane lines.
-
Utilizes a Region of Interest (ROI) masking to focus detection on relevant road areas, improving accuracy and performance.
-
Establishes virtual lane boundaries to monitor vehicle movement.
-
Detects and flags real-time lane violations with a prominent red bounding box and"Lane Violation" overlay.
-
Automatically logs all violations to a CSV file for further analysis.
-
Utilizes centroid-based tracking to monitor vehicle movement across frames.
-
Calculates vehicle speed based on pixel movement and flags vehicles exceeding a configurable speed threshold (default: 15 pixels/frame).
-
Displays a warning marker for rash driving incidents.
-
Extracts the lower 30% of vehicle bounding boxes to simulate number plate regions.
-
Analyzes brightness and visibility, issuing a "Plate Not Visible" warning for unclear plates.
-
Records all detected violations, including Lane Violations, Rash Driving, and Plate Visibility Issues.
-
Exports logs to a CSV file with detailed information such as timestamp, frame number, vehicle ID, class, confidence, bounding box, and specific violation parameters.
-
Generates summary statistics for quick overview and reporting.
- Produces a fully processed video (
urbanflow_output.mp4) with all overlays, including:- Bounding boxes, class labels, and confidence scores.
- Real-time vehicle counts and traffic density levels.
- Adaptive signal countdown timer.
- Violation markers for lane infractions, rash driving, and plate visibility.
UrbanFlow is built using a robust and modern tech stack, leveraging leading libraries for computer vision, deep learning, and web development:
| Component | Technology | Description |
|---|---|---|
| Programming Language | Python 3.10+ | The core language for all modules. |
| Deep Learning Framework | Ultralytics YOLOv8/YOLOv11 | State-of-the-art models for object detection and classification. |
| Computer Vision | OpenCV | Essential library for image processing, lane detection, and video handling. |
| Object Tracking | Custom Centroid Tracker (Python) | Developed in-house for efficient vehicle tracking and speed estimation. |
| Data Processing | Pandas, NumPy | For efficient data manipulation, analysis, and CSV logging. |
| Web User Interface | Streamlit | For creating an interactive and user-friendly web application. |
| Visualization | Matplotlib, Plotly | For generating charts and visualizing data within the Streamlit app. |
| File / Folder | Description |
|---|---|
app.py |
Main Streamlit dashboard β handles video upload, live preview, adaptive signal display, and violation analytics UI. |
processor.py |
Core VideoProcessor class β runs vehicle detection, tracking, lane detection, and violation logging on each frame. |
train.py |
Script for training/fine-tuning custom YOLO models on traffic data. |
config.py |
Central configuration β vehicle detection settings, density thresholds, UI settings, and signal-timing logic. |
utils/ |
Helper/utility modules used across the project. |
requirements.txt |
Python dependencies required to run the project. |
app_backup.py |
Earlier backup version of the main app (kept for reference). |
(No Dockerization found. Consider adding Docker support.)
# UrbanFlow: AI-Based Intelligent Traffic Monitoring and Adaptive Signal System
# Requirements File
# Install with: pip install -r requirements.txt
# Core Computer Vision and Deep Learning
ultralytics>=8.0.200 # YOLOv8 for vehicle detection
opencv-python>=4.8.0 # OpenCV for image processing
supervision>=0.18.0 # Object tracking and annotation utilities
# Data Processing and Analysis
numpy>=1.24.0 # Numerical operations
pandas>=2.0.0 # Data manipulation for violation logging
matplotlib>=3.7.0 # Plotting and visualization
# Web Application Framework
streamlit>=1.28.0 # Web UI for the application
# Additional Utilities
Pillow>=10.0.0 # Image processing utilities
tqdm>=4.65.0 # Progress bars for processing
pyyaml>=6.0 # YAML configuration parsing
# Optional: For faster video processing (if available on system)
# imageio-ffmpeg>=0.4.9
Follow these steps to run UrbanFlow locally:
- Clone the repository
git clone https://github.com/shubham333k/UrbanFlow.git
cd UrbanFlow- (Optional but recommended) Create a virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies
pip install -r requirements.txt- Run the Streamlit app
streamlit run app.py- Open in browser β Streamlit will auto-launch at
http://localhost:8501. Upload a traffic video from the sidebar and click "βΆ INITIATE ANALYSIS" to start processing.
| Method | Endpoint | Description |
|---|---|---|
| GET | /example | Example API endpoint. |
(Review app.py, api.py, or backend folders for actual API endpoints.) |
(No specific documentation files found. Add links to detailed documentation here.)
(No explicit unit test files found. Describe testing strategy here.)
(No CI configuration found. Describe CI/CD setup here.)
We welcome contributions to UrbanFlow! If you have suggestions for improvements, new features, or bug fixes, please feel free to:
-
Fork the repository.
-
Create a new branch (
git checkout -b feature/YourFeature). -
Make your changes and ensure they adhere to the project's coding style.
-
Commit your changes (
git commit -m 'Add new feature'). -
Push to the branch (
git push origin feature/YourFeature). -
Open a Pull Request with a clear description of your changes.
This project is licensed under the MIT License - see the LICENSE file for details.
For any questions or inquiries, please reach out to the project maintainer:
- Shubham Kumar - GitHub Profile
UrbanFlow: Empowering Smarter Cities with AI.