An AI-powered crowd monitoring web application that uses YOLOv8 to detect people in real-time from camera feeds, calculates crowd density, classifies congestion levels, generates alerts, stores data, and sends email notifications to authority personnel.
- C Hridya Ajay (ASI23CS071)
- Dayana Shiju (ASI23CS075)
- Gagana Parvathi (ASI23CS088)
- Submitted to: Ms Raghi R Menon
- Real-time Crowd Detection: Uses YOLOv8n model to detect people from camera feeds
- Density Calculation: Calculates people per square meter in defined zones
- Congestion Classification: Low (< 5 people), Medium (≥ 5), High (≥ 10)
- Alert System: Automatic dashboard alerts and email notifications
- Bus Monitoring: Special mode for tracking bus entry/exit with line crossing detection
- Multi-zone Support: 5 simulated zones with individual crowd tracking
- Analytics Dashboard: Historical data visualization with Chart.js
- Mobile Responsive: Works on all devices with bottom navigation
- Backend: Python, Flask, Flask-CORS
- AI Model: YOLOv8n (Ultralytics)
- Computer Vision: OpenCV
- Database: SQLite (
crowd.db) - Email: Gmail SMTP with App Passwords
- Frontend: HTML5, CSS3, JavaScript (Vanilla)
- Charts: Chart.js
- Icons: Font Awesome
- Fonts: Google Fonts (Poppins, Space Mono)
pip install -r requirements.txtEdit app.py and update these settings:
EMAIL_USER = "your_email@gmail.com"
EMAIL_PASSWORD = "your_16_char_app_password" # Gmail App Password
EMAIL_RECIPIENTS = [
"recipient1@gmail.com",
"recipient2@gmail.com",
"recipient3@gmail.com"
]python app.py- Main Application: http://localhost:5000
- Login: Use any credentials (prototype mode)
- Standalone Demo: Open
prototype.htmldirectly in browser (no server needed)
- Simple authentication gateway
- Any credentials accepted for prototype
- Real-time crowd statistics
- Alert status overview
- Quick navigation to all features
- Recent alerts list
- Live MJPEG video stream with YOLOv8 detections
- Real-time people count and density
- System information display
- Toggle between Normal and Bus modes
- Track passengers entering/exiting bus
- Occupancy percentage with color-coded progress bar
- Live passenger trend chart
- 5-zone facility visualization
- Real-time zone status with color coding
- Animated markers for high congestion
- Zone list with detailed statistics
- Historical crowd data visualization
- Line chart: Last 50 readings
- Doughnut chart: Congestion level distribution
- Bar chart: 24-hour hourly averages
- Summary statistics (current, peak, average)
- Alert history with acknowledgment
- Email notification status
- Test email functionality
- Unacknowledged alert tracking
- Complete self-contained demo
- Simulated crowd data with realistic patterns
- All features in single HTML file
- No server required
CAMERA_SOURCE = 0 # 0 = webcam, or IP camera URL
ZONE_AREA = 50.0 # square metres per zoneTHRESHOLD_MED = 5 # Medium congestion threshold
THRESHOLD_HIGH = 10 # High congestion threshold
BUS_CAPACITY = 45 # Bus capacity for occupancy tracking- Medium Cooldown: 120 seconds
- High Cooldown: 60 seconds
- Recipients: Up to 3 authority personnel
- Format: Styled HTML with crowd statistics
| Method | Endpoint | Description |
|---|---|---|
| GET | /video |
MJPEG live stream with detections |
| GET | /api/crowd |
Current crowd statistics |
| GET | /api/alerts/history |
Complete alert history |
| GET | /api/history |
Last 50 crowd records |
| GET | /api/analytics |
Hourly aggregated data |
| GET | /api/zones |
5-zone crowd data |
| GET | /api/set_mode/<mode> |
Switch detection mode |
| POST | /api/acknowledge/<id> |
Acknowledge alert |
| POST | /api/email/test |
Send test email |
| GET | /api/status |
System health check |
CREATE TABLE crowd_history (
id INTEGER PRIMARY KEY AUTOINCREMENT,
timestamp TEXT,
count INTEGER,
density REAL,
level TEXT
);CREATE TABLE alerts (
id INTEGER PRIMARY KEY AUTOINCREMENT,
timestamp TEXT,
level TEXT,
message TEXT,
people_count INTEGER,
acknowledged INTEGER DEFAULT 0,
email_sent INTEGER DEFAULT 0
);- Enable 2-Step Verification on your Google Account
- Go to Security → App Passwords
- Create new app password named "CrowdWatch"
- Copy the 16-character password
- Update
EMAIL_PASSWORDinapp.py
crowdwatch/
├── app.py # Flask backend with YOLOv8
├── requirements.txt # Python dependencies
├── yolov8n.pt # YOLOv8 model file
├── crowd.db # SQLite database
├── index.html # Login page
├── dashboard.html # Main dashboard
├── live.html # Live video monitoring
├── busmonitor.html # Bus entry/exit tracking
├── map.html # Zone visualization
├── analytics.html # Data analytics
├── alerts.html # Alert management
├── prototype.html # Standalone demo
├── static/
│ ├── style.css # Global styles
│ └── app.js # Shared JavaScript
└── README.md # This file
- Chrome 80+
- Firefox 75+
- Safari 13+
- Edge 80+
- Prototype accepts any login credentials
- Email passwords should use App Passwords, not account passwords
- Camera feed is accessible on local network only
- No user authentication in prototype mode
- Check if webcam is connected and not used by other apps
- Try changing
CAMERA_SOURCEto different index or IP URL - Ensure OpenCV can access the camera
- Verify Gmail App Password is correctly set
- Check if 2-Step Verification is enabled
- Ensure recipient emails are valid
- YOLOv8n is optimized but still CPU-intensive
- Consider reducing video resolution or frame rate
- Use GPU acceleration if available
- Detection Response: < 2 seconds
- Update Frequency: 2 seconds for UI, 1 second for video
- Database Logging: Every 30 frames (~1 second)
- Memory Usage: ~500MB (including model)
This project is for educational purposes. Use responsibly and comply with local privacy laws when monitoring public spaces.
CrowdWatch - Making public spaces safer through AI-powered crowd monitoring 🚶♂️📊