Pro-Vision is a production-ready, real-time driver drowsiness detection system using edge computing and advanced computer vision. It classifies driver states into AWAKE, DROWSY, or SLEEPING with multi-level alerts.
✅ Real-time Detection - 30+ FPS processing
✅ Advanced Analytics - Blink detection, yawn detection, fatigue scoring
✅ Multi-level Alerts - Info/Warning/Critical with audio & visual
✅ Event Logging - Persistent JSON logs with filtering
✅ Production Architecture - Modular, configurable, scalable
✅ Easy Deployment - Single command startup, Streamlit web UI
- Python 3.9+
- Webcam (for live mode)
- Linux/Mac/Windows
# Clone or download the repository
cd pro-vision-v2
# Install dependencies
pip install -r requirements.txt
# Run the dashboard
streamlit run app.pyThe dashboard opens at http://localhost:8501
┌─────────────────────────────────────────┐
│ Video Input (Webcam) │
└──────────────────┬──────────────────────┘
│
▼
┌──────────────────────────────┐
│ detection_engine.py │
│ ├─ FaceDetector │
│ ├─ DrowsinessClassifier │
│ └─ FrameAnnotator │
└──────────────────┬───────────┘
│
▼
┌──────────────────────────┐
│ alert_system.py │
│ ├─ AlertManager │
│ └─ EventLogger │
└──────────┬───────────────┘
│
▼
┌──────────────────────────────┐
│ app.py (Streamlit) │
│ ├─ Live Feed │
│ ├─ Real-time Metrics │
│ ├─ Charts & Analytics │
│ └─ Event Logs │
└──────────────────────────────┘
Edit config.json to tune the system:
{
"detection": {
"face_scale_factor": 1.1, // Higher = faster but less accurate
"face_min_neighbors": 6, // Higher = fewer false positives
"eye_scale_factor": 1.1,
"eye_min_neighbors": 5,
"clahe_clip_limit": 2.0 // Image enhancement strength
},
"drowsiness": {
"history_window": 15, // Frames to average (delay)
"blink_threshold_frames": 2, // Frames to consider a blink
"eye_closed_ratio": 0.4, // % eyes closed = drowsy
"drowsy_threshold": 35, // Score threshold for DROWSY
"sleep_threshold": 75 // Score threshold for SLEEPING
},
"performance": {
"skip_frames": 2, // Process every Nth frame
"frame_width": 640,
"frame_height": 480,
"target_fps": 30
},
"alerts": {
"beep_cooldown": 2.0, // Seconds between alerts
"warning_threshold": 35,
"critical_threshold": 75
}
}- Face Detection: Haar Cascade (fast, edge-optimized)
- Eye Detection: Haar Cascade in face ROI
- Smile/Yawn Detection: Optional feature for fatigue analysis
- Rolling 15-frame window tracks eye closure
- Hysteresis prevents false positives
- Score decays when eyes open (recovery time)
- Thresholds: DROWSY (>35) → SLEEPING (>75)
- Distinguishes between normal blinks and eye closure
- Tracks blink rate (blinks/30s)
- Abnormal patterns trigger warnings
| Level | Trigger | Response |
|---|---|---|
| INFO | Normal operation | Green border, ✅ message |
| WARNING | Score > 35 | Orange border, |
| CRITICAL | Score > 75 | Red border, 🚨 alert + beep |
- Persistent JSON log (
vision_events.json) - Filterable by alert level
- Timestamp, score, and message
- Export for analysis
- Camera Mode: Live Camera or Demo Mode
- Eye Sensitivity: 3-20 (lower = more sensitive)
- Frame Skip: Process every Nth frame (1-5)
- Audio/Visual Alerts: Toggle on/off
- Event Logs: View, filter, export, clear
- Live Video Feed with annotated detections
- Real-time Metrics: Status, score, eyes detected, blink rate
- Drowsiness Chart: Score over time
- Blink Rate Chart: Blink frequency trend
Process every 2nd or 3rd frame (configurable) while maintaining smooth UI:
skip_frames = 2
if frame_count % skip_frames == 0:
detect_faces_and_eyes()Benefit: 2x-3x faster with minimal latency (50-100ms delay)
Contrast Limited Adaptive Histogram Equalization improves detection in poor lighting:
clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8,8))
enhanced = clahe.apply(gray_frame)Eyes are searched only in face region:
roi = frame[face_y:face_y+face_h, face_x:face_x+face_w]
eyes = detect_eyes(roi) # Much faster than full frame# Optional: Replace Haar Cascades with YOLO/RetinaFace
from ultralytics import YOLO
face_model = YOLO("yolov8n-face.pt")
faces = face_model.predict(frame)- Track multiple drivers simultaneously
- Per-person thresholds and profiles
- Fatigue prediction (predicts drowsiness before critical)
- Driving pattern analysis
- Integration with CAN bus (vehicle data)
- Upload alerts to backend
- Mobile notifications
- Fleet monitoring dashboard
# Check available cameras
python -c "import cv2; print(cv2.VideoCapture(0).isOpened())"
# Try different camera indices
# In app.py, change: cap = cv2.VideoCapture(0) → cap = cv2.VideoCapture(1)- Increase
skip_framesin settings (3-4) - Reduce
frame_width/frame_heightin config - Lower
face_scale_factorto 1.05
- Increase
eye_min_neighborsin config (7-8) - Adjust
eye_closed_ratio(0.5-0.6) - Increase
history_window(20-25)
- Ensure good lighting
- Remove glasses or adjust angle
- Lower
eye_min_neighbors(3-4) - Increase
eye_sensitivityslider (15-18)
pro-vision-v2/
├── app.py # Streamlit dashboard (main entry point)
├── detection_engine.py # Core detection logic
├── alert_system.py # Alert & logging system
├── config.json # Tunable parameters
├── requirements.txt # Python dependencies
├── vision_events.json # Event log (auto-generated)
└── README.md # This file
- No cloud transmission: All processing local
- No persistent video: Frames not stored
- Logs only: Timestamps and status changes
- Opt-out: Disable logging in config
Free to use and modify. Built for educational use only.
Want to improve Pro-Vision?
- Better Detection: Experiment with different Haar Cascades
- New Features: Add blink rate alerts, fatigue prediction
- Performance: Optimize with GPU acceleration (CUDA)
- UI: Enhance Streamlit dashboard design
- Issues: Check troubleshooting section
- Enhancement: Modify
config.jsonfor your use case - Integration: Adapt detection_engine.py for custom pipelines
streamlit run app.pyFROM python:3.9-slim
WORKDIR /app
COPY . .
RUN pip install -r requirements.txt
CMD ["streamlit", "run", "app.py"]- Push repo to GitHub
- Go to streamlit.io/cloud
- Connect repo and deploy
| Metric | Value | Notes |
|---|---|---|
| FPS | 25-30 | 640x480, skip_frames=2 |
| Latency | 100-150ms | Face detection + scoring |
| Memory | ~200MB | Python + OpenCV |
| CPU | 30-40% | Single core (i7 @ 2.6GHz) |
Pro-Vision v2.0 - Built for Production ✅
- LABBAALLI Hamza
- ID-BOUBRIK Abdelouahed
- MAAROUF Yassine
- IDDAHA Soumaya
Thanks to all contributors who have helped this project!