A Flask-based web application that uses YOLOv5 and OpenCV to detect and analyze crowd density in video files. The system provides real-time people counting, heatmap visualization, and comprehensive analytics.
- YOLOv5 Person Detection: Uses state-of-the-art YOLO model for accurate person detection
- Video Processing: Frame-by-frame analysis with OpenCV
- Heatmap Generation: Visual representation of crowd density patterns
- Real-time Analytics: People counting, peak detection, and statistical analysis
- Multi-format Support: Handles MP4, AVI, MOV, MKV, FLV, and WMV files
- Responsive Web Interface: Clean, Bootstrap-based design
- Drag & Drop Upload: Intuitive file upload with validation
- Real-time Progress: Processing status and progress tracking
- Comprehensive Results: Detailed analytics and visualizations
- Download Functionality: Get processed videos with overlays
- Cloud-Ready: Optimized for deployment on Render, Railway, or Heroku
- Lightweight: No heavy GPU dependencies for easy deployment
- Scalable Architecture: Modular design with separate utilities
- Error Handling: Comprehensive error handling and user feedback
- Security: File validation and secure upload handling
crowd-density-detection/
├── static/
│ ├── css/
│ │ └── style.css # Custom styling
│ ├── js/
│ │ └── upload.js # Frontend interactions
│ ├── uploads/ # Uploaded video files
│ └── processed/ # Processed video outputs
├── templates/
│ ├── index.html # Main upload page
│ └── results.html # Results page
├── utils/
│ ├── detection.py # YOLOv5 detection logic
│ ├── heatmap.py # Heatmap generation
│ └── video_processor.py # Video processing pipeline
├── app.py # Flask application
├── main.py # Entry point
├── Procfile # Heroku/Railway deployment
└── README.md # This file
- Python 3.11+
- pip package manager
- Clone the repository:
git clone https://github.com/yourusername/crowd-density-detection.git
cd crowd-density-detection- Install dependencies:
pip install -r requirements.txt- Set environment variables:
export SESSION_SECRET="your-secret-key-here"- Run the application:
python main.py- Open browser to
http://localhost:5000
- Push code to GitHub
- Connect Render to your repository
- Set build command:
pip install -r requirements.txt - Set start command:
gunicorn --bind 0.0.0.0:$PORT main:app - Add environment variable:
SESSION_SECRET
- Push code to GitHub
- Import project in Railway
- Railway will auto-detect Python and use the Procfile
- Add environment variable:
SESSION_SECRET
- Upload Video: Navigate to the home page and upload a video file
- Processing: The system will analyze the video frame by frame
- Results: View comprehensive analytics including:
- Total people detected
- Peak crowd count and timing
- Average people per frame
- Density heatmap visualization
- Download: Get the processed video with bounding boxes and overlays
- MP4 (recommended)
- AVI
- MOV
- MKV
- FLV
- WMV
Maximum file size: 100MB
- YOLOv5: Loaded from PyTorch Hub for person detection
- Confidence Threshold: 0.5 (configurable)
- CPU Optimized: Works without GPU requirements
- OpenCV: Frame-by-frame processing
- Real-time Analysis: People counting and tracking
- Heatmap Generation: Grid-based density visualization
- Flask: Python web framework
- Bootstrap: Responsive UI components
- Gunicorn: WSGI server for production
Key settings in app.py:
MAX_CONTENT_LENGTH: File size limit (100MB)ALLOWED_EXTENSIONS: Supported video formatsUPLOAD_FOLDER: Upload directoryPROCESSED_FOLDER: Output directory
- Detection logic: Modify
utils/detection.py - Video processing: Update
utils/video_processor.py - Heatmap generation: Edit
utils/heatmap.py - Frontend: Update templates and static files
GET /: Main upload pagePOST /upload: Handle video uploadGET /process/<file_id>: Process video and show resultsGET /download/<file_id>: Download processed video
- Model Loading: First run downloads YOLOv5 model (may take time)
- Memory: Large videos may require more RAM
- Processing Time: Depends on video length and resolution
- Use MP4 format for best compatibility
- Keep videos under 10 minutes for faster processing
- Lower resolution videos process faster
MIT License - feel free to use and modify
- Fork the repository
- Create feature branch
- Submit pull request
For issues and questions, please open a GitHub issue or contact the maintainers.