Skip to content

Udith-creates/Intellignet-Traffic-Incident-Detection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🚦 Smart Traffic Management Dashboard

An AI-powered real-time traffic monitoring system that detects emergency vehicles and traffic accidents using YOLO object detection models with automated email alerts.

✨ Features

  • πŸš‘ Emergency Vehicle Detection - Real-time identification of ambulances, fire trucks, and police vehicles
  • 🚨 Accident Detection - Automatic detection of traffic accidents with visual alerts
  • πŸ“§ Email Alerts - Automated email notifications with accident images and GPS location coordinates
  • πŸŽ₯ Real-time Video Processing - Live video analysis with side-by-side detection results
  • 🌍 GPS Integration - Browser-based geolocation capture for accident incidents
  • βš™οΈ Configurable Confidence - Adjustable detection confidence threshold (0.1 - 1.0)
  • πŸ“± Web Dashboard - Interactive Streamlit web interface

πŸ“‹ Prerequisites

  • Python 3.8 or higher
  • CUDA-capable GPU (recommended for real-time processing)
  • Webcam or video files for input

πŸš€ Installation

  1. Clone or extract the project

    cd "Intelligent Traffic Incident Detection"
  2. Install dependencies

    pip install -r requirements.txt
  3. Verify CUDA installation (optional but recommended)

    python -c "import torch; print('CUDA available:', torch.cuda.is_available())"

βš™οΈ Configuration

Environment Variables

Set the following environment variables for email alerts functionality:

# Windows PowerShell
$env:SENDER_EMAIL = "your_email@gmail.com"
$env:SENDER_PASSWORD = "your_app_password"
$env:RECEIVER_EMAIL = "alert_recipient@gmail.com"
# Windows CMD
set SENDER_EMAIL=your_email@gmail.com
set SENDER_PASSWORD=your_app_password
set RECEIVER_EMAIL=alert_recipient@gmail.com
# Linux/Mac
export SENDER_EMAIL="your_email@gmail.com"
export SENDER_PASSWORD="your_app_password"
export RECEIVER_EMAIL="alert_recipient@gmail.com"

Note: For Gmail, use an App Password instead of your regular password.

πŸ“– Usage

Run Web Dashboard

streamlit run app.py

The dashboard will open at http://localhost:8501

Dashboard Features:

  • Upload traffic video files (mp4, avi, mov, webm)
  • Adjust confidence threshold with slider
  • View real-time detection results
  • Monitor email alert status
  • See accident detection alerts

Run Standalone Notebook

jupyter notebook accident_detection.ipynb

Processes video/webcam feed and saves output to output_video/ folder.

πŸ“ Project Structure

β”œβ”€β”€ app.py                          # Main Streamlit web application
β”œβ”€β”€ accident_detection.ipynb        # Standalone Jupyter notebook
β”œβ”€β”€ requirements.txt                # Python dependencies
β”œβ”€β”€ best.pt                         # Accident detection model
β”œβ”€β”€ emergency.pt                    # Emergency vehicle detection model
β”œβ”€β”€ alarm.wav                       # Audio alert sound
β”‚
β”œβ”€β”€ Model Results and Details/
β”‚   β”œβ”€β”€ data.yaml                   # Dataset configuration
β”‚   β”œβ”€β”€ train.py                    # Model training script
β”‚   β”œβ”€β”€ yolo12m.pt                  # YOLOv12 medium pretrained model
β”‚   β”œβ”€β”€ yolo11n.pt                  # YOLOv11 nano pretrained model
β”‚   β”‚
β”‚   β”œβ”€β”€ Accident model results/     # Accident model training results
β”‚   β”‚   β”œβ”€β”€ args.yaml
β”‚   β”‚   β”œβ”€β”€ results.csv
β”‚   β”‚   └── [confusion matrices, PR curves, etc.]
β”‚   β”‚
β”‚   └── Vehicle Classification/     # Emergency vehicle model results
β”‚       β”œβ”€β”€ args.yaml
β”‚       β”œβ”€β”€ results.csv
β”‚       β”œβ”€β”€ weights/
β”‚       β”‚   β”œβ”€β”€ best.pt
β”‚       β”‚   └── last.pt
β”‚       └── [training visualizations]
β”‚
β”œβ”€β”€ Testing Videos/                 # Sample video files
β”‚   β”œβ”€β”€ rear_collision_10.mp4
β”‚   β”œβ”€β”€ stock-footage-a-uk-ambulance...webm
β”‚   └── WhatsApp Video 2025-12-05...mp4
β”‚
└── output_video/                   # Generated video outputs

πŸ€– Models

Emergency Vehicle Detection Model

  • File: emergency.pt
  • Framework: YOLOv12
  • Classes: Ambulance, Fire Truck, Police, Vehicle
  • Dataset: Indian Emergency Vehicles (Roboflow)
  • License: CC BY 4.0

Accident Detection Model

  • File: best.pt
  • Framework: YOLO
  • Purpose: Real-time accident/collision detection
  • Training Data: Custom accident dataset

πŸ”§ Training (Advanced)

To retrain models with new data:

python Model\ Results\ and\ Details\train.py

Training Configuration:

  • Epochs: 120
  • Batch Size: 8 (RTX 3050 compatible)
  • Learning Rate: 0.001
  • Optimizer: AdamW
  • Image Size: 640x640

πŸ“Š Model Performance

Both models include comprehensive evaluation metrics:

  • Confusion matrices
  • Precision-Recall (PR) curves
  • F1, Precision, and Recall curves
  • Training/validation visualizations
  • Results CSV files

πŸ› Troubleshooting

Streamlit Won't Start

  • Issue: Exit code 1
  • Solution: Set environment variables for email credentials
    $env:SENDER_EMAIL = "email@gmail.com"
    $env:SENDER_PASSWORD = "password"
    $env:RECEIVER_EMAIL = "recipient@gmail.com"

GPU Not Detected

  • Ensure NVIDIA CUDA Toolkit is installed
  • Update NVIDIA drivers
  • Verify PyTorch installation: python -c "import torch; print(torch.cuda.is_available())"

Model Not Found

  • Ensure best.pt and emergency.pt are in the project root directory
  • Check file paths are correct

Email Alerts Not Working

  • Verify environment variables are set correctly
  • Use App Password for Gmail (not regular password)
  • Ensure 5-minute cooldown between alerts
  • Check SENDER_EMAIL and RECEIVER_EMAIL are valid

πŸ“¦ Dependencies

See requirements.txt for complete list:

  • streamlit - Web UI framework
  • opencv-python - Video processing
  • ultralytics - YOLO models
  • pygame - Audio alerts
  • torch - Deep learning framework
  • numpy - Numerical operations
  • Pillow - Image processing

πŸ“ Notes

  • Email alerts have a 5-minute cooldown to prevent spam
  • Confidence threshold default: 0.3 (adjustable in sidebar)
  • GPS location requires browser permission
  • Accident frame screenshots are automatically saved and deleted after email

🎯 Future Enhancements

  • Real-time traffic flow analysis
  • Traffic congestion prediction
  • Multi-camera support
  • Database logging for incident history
  • Mobile app integration
  • SMS alerts
  • Integration with traffic management systems

πŸ“§ Support

For issues or questions, refer to:

πŸ“„ License

Dataset License: CC BY 4.0 Project: For educational and commercial use.


Version: 1.0
Last Updated: December 2025

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors