Skip to content

shubham333k/UrbanFlow

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

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

Repository files navigation

UrbanFlow

✨ Project Overview

PythonYOLOStreamlitOpenCVLicense

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.

πŸš€ Key Features

UrbanFlow integrates multiple advanced computer vision and AI techniques to provide a holistic traffic management solution:

1. Advanced Vehicle Detection & Classification

  • 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.

2. Real-time Vehicle Counting

  • 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.

3. Dynamic Traffic Density Estimation

  • 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

4. Adaptive Traffic Signal Control

  • 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.

5. Robust Lane Detection

  • 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.

6. Automated Lane Violation Detection

  • 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.

7. Intelligent Rash Driving Detection

  • 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.

8. Simulated Number Plate Visibility Check

  • 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.

9. Comprehensive Violation Logging System

  • 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.

10. Rich Output Video Generation

  • 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.

πŸ› οΈ Tech Stack

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.

πŸ“‚ Project Structure

#-project-structure

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).

πŸ—οΈ Architecture Diagram

urbanflow Architecture

🐳 Dockerization

(No Dockerization found. Consider adding Docker support.)

πŸ“‹ Requirements

# 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

πŸ–₯️ Installation & How to Run

#-installation--how-to-run

Follow these steps to run UrbanFlow locally:

  1. Clone the repository
   git clone https://github.com/shubham333k/UrbanFlow.git
   cd UrbanFlow
  1. (Optional but recommended) Create a virtual environment
   python -m venv venv
   source venv/bin/activate   # On Windows: venv\Scripts\activate
  1. Install dependencies
   pip install -r requirements.txt
  1. Run the Streamlit app
   streamlit run app.py
  1. 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.

🌐 API Endpoints

Method Endpoint Description
GET /example Example API endpoint.
(Review app.py, api.py, or backend folders for actual API endpoints.)

πŸ”— Deployment

Deployment Link

πŸ“Έ Screenshots

Urbanflow Dashboard Screenshot2 Urbanflow Dashboard Screenshot

πŸ“š Documentation

(No specific documentation files found. Add links to detailed documentation here.)

πŸ§ͺ Unit Tests

(No explicit unit test files found. Describe testing strategy here.)

βš™οΈ Continuous Integration (CI)

(No CI configuration found. Describe CI/CD setup here.)

🀝 Contributing

We welcome contributions to UrbanFlow! If you have suggestions for improvements, new features, or bug fixes, please feel free to:

  1. Fork the repository.

  2. Create a new branch (git checkout -b feature/YourFeature).

  3. Make your changes and ensure they adhere to the project's coding style.

  4. Commit your changes (git commit -m 'Add new feature').

  5. Push to the branch (git push origin feature/YourFeature).

  6. Open a Pull Request with a clear description of your changes.

πŸ“„ License

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

πŸ“ž Contact

For any questions or inquiries, please reach out to the project maintainer:


UrbanFlow: Empowering Smarter Cities with AI.

About

Intelligent urban traffic management and infrastructure optimization system using AI and data analysis.

Topics

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages