An AI-powered real-time traffic monitoring system that detects emergency vehicles and traffic accidents using YOLO object detection models with automated email alerts.
- π 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
- Python 3.8 or higher
- CUDA-capable GPU (recommended for real-time processing)
- Webcam or video files for input
-
Clone or extract the project
cd "Intelligent Traffic Incident Detection"
-
Install dependencies
pip install -r requirements.txt
-
Verify CUDA installation (optional but recommended)
python -c "import torch; print('CUDA available:', torch.cuda.is_available())"
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.
streamlit run app.pyThe 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
jupyter notebook accident_detection.ipynbProcesses video/webcam feed and saves output to output_video/ folder.
βββ 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
- File:
emergency.pt - Framework: YOLOv12
- Classes: Ambulance, Fire Truck, Police, Vehicle
- Dataset: Indian Emergency Vehicles (Roboflow)
- License: CC BY 4.0
- File:
best.pt - Framework: YOLO
- Purpose: Real-time accident/collision detection
- Training Data: Custom accident dataset
To retrain models with new data:
python Model\ Results\ and\ Details\train.pyTraining Configuration:
- Epochs: 120
- Batch Size: 8 (RTX 3050 compatible)
- Learning Rate: 0.001
- Optimizer: AdamW
- Image Size: 640x640
Both models include comprehensive evaluation metrics:
- Confusion matrices
- Precision-Recall (PR) curves
- F1, Precision, and Recall curves
- Training/validation visualizations
- Results CSV files
- 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"
- Ensure NVIDIA CUDA Toolkit is installed
- Update NVIDIA drivers
- Verify PyTorch installation:
python -c "import torch; print(torch.cuda.is_available())"
- Ensure
best.ptandemergency.ptare in the project root directory - Check file paths are correct
- 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
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
- 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
- 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
For issues or questions, refer to:
Dataset License: CC BY 4.0 Project: For educational and commercial use.
Version: 1.0
Last Updated: December 2025