A sophisticated real-time drowsiness detection system designed to enhance road safety through AI-powered monitoring.
- Overview
- Key Features
- Technology Stack
- System Architecture
- Installation Guide
- Usage Instructions
- API Documentation
- Configuration
- Troubleshooting
- Contributing
- License
DriveSafe is an intelligent drowsiness detection system that leverages cutting-edge computer vision and machine learning technologies to monitor driver alertness in real-time. The system uses facial landmark detection and deep learning models to identify signs of drowsiness, including eye closure patterns and yawning behavior.
- Commercial Fleet Management: Monitor driver fatigue in logistics and transportation
- Personal Safety: Individual drivers seeking enhanced safety measures
- Research & Development: Academic studies on driver behavior and fatigue
- Automotive Integration: Potential integration with vehicle safety systems
- Real-time Eye Tracking: Monitors eye aspect ratio (EAR) for precise drowsiness detection
- Yawning Detection: AI-powered mouth analysis using ResNet50V2 deep learning model
- Facial Landmark Recognition: 468-point MediaPipe face mesh for accurate feature detection
- Adaptive Thresholding: Dynamic calibration system for personalized detection sensitivity
- Modern Web Interface: Responsive design with dark/light mode support
- Real-time Monitoring Dashboard: Live statistics and status indicators
- Interactive Controls: Adjustable sensitivity, threshold settings, and alert preferences
- Comprehensive Statistics: Detailed analytics including alert counts and monitoring duration
- RESTful API Architecture: Clean, well-documented API endpoints
- Cross-Origin Resource Sharing (CORS): Seamless frontend-backend communication
- Error Handling & Recovery: Robust error management and connection recovery
- Performance Optimization: Efficient frame processing and resource management
- Multi-level Alert System: Visual and audio alerts with customizable sensitivity
- Connection Monitoring: Real-time backend connectivity status
- Troubleshooting Tools: Built-in diagnostic and reset capabilities
- Data Privacy: Local processing with no external data transmission
- Python 3.10.11: Core programming language
- Flask 3.0.0: Lightweight web framework
- TensorFlow 2.15.0: Deep learning model inference
- OpenCV 4.9.0.80: Computer vision and image processing
- MediaPipe 0.10.8: Facial landmark detection
- NumPy 1.24.3: Numerical computing
- HTML5: Semantic markup structure
- CSS3: Modern styling with Tailwind CSS
- JavaScript (ES6+): Interactive functionality
- WebRTC: Real-time camera access
- Canvas API: Image processing and capture
- Flask-CORS 4.0.0: Cross-origin request handling
- Gdown 4.7.1: Model file management
- python-dotenv: Environment variable management
graph TB
A[Web Browser] --> B[Frontend Interface]
B --> C[WebRTC Camera]
B --> D[REST API Client]
D --> E[Flask Backend]
E --> F[MediaPipe Face Detection]
E --> G[TensorFlow Model]
E --> H[OpenCV Processing]
F --> I[Facial Landmarks]
G --> J[Yawning Detection]
H --> K[Image Processing]
I --> L[Drowsiness Analysis]
J --> L
K --> L
L --> M[Alert System]
M --> N[Visual Alerts]
M --> O[Audio Alerts]
git clone https://github.com/aadii-chavan/Driver-Drowsiness.git
cd Driver-Drowsinesspython -m venv drowsiness_env
# On Windows:
drowsiness_env\Scripts\activate
# On macOS/Linux:
source drowsiness_env/bin/activatepip install -r requirements.txtThe app will attempt to download the model automatically on first run. If it fails, you can manually download it:
- Run the helper script:
python download_model.py
- Or manually download from Google Drive, rename to
resnet50v2_model.keras, and place it in themodel/folder.
Note: If the model is missing, the app will still run, but yawning detection will use a fallback heuristic.
python app.py- The Flask server will start (default:
http://localhost:5001). - The backend will auto-detect your camera. If you have multiple cameras, it will try all available indices.
Open your browser and go to:
http://localhost:5001
- Launch the Application: Start the Flask server and open the web interface.
- Grant Camera Permission: Allow browser access to your webcam when prompted.
- Calibrate the System: Click "Calibrate" and follow the on-screen instructions.
- Start Monitoring: Click "Start Monitoring" to begin drowsiness detection.
- Alert Sensitivity: Adjustable from Very Low to Very High.
- Eye Threshold: Adjustable (0.15 - 0.35), auto-calibrated during calibration.
- Night Mode: Optimized for low-light conditions.
- Sound Alerts: Enable/disable audio notifications.
- Dark Mode: Toggle between light and dark themes.
- Face Detection Status: Whether a face is currently detected.
- Eye Status: Open/closed state of eyes.
- Mouth Status: Normal/yawning state.
- EAR Value: Current Eye Aspect Ratio measurement.
- Alert Count: Total number of drowsiness alerts triggered.
- Monitor Time: Duration of current monitoring session.
http://localhost:5001/api
Check API status and model availability.
Calibrate the eye threshold using provided frames.
Perform drowsiness detection on a single frame.
See the full API documentation in the code or below in this README.
- All configuration is managed via
config.pyand environment variables (see.env.example). - You can override defaults by creating a
.envfile in the project root.
Example .env:
FLASK_ENV=development
FLASK_DEBUG=True
FLASK_HOST=0.0.0.0
FLASK_PORT=5001
MODEL_FILE_ID=1UInMiIbaHChmI-KSQ7VRMp_53RZpSDd4
MODEL_PATH=./model/resnet50v2_model.keras
DEFAULT_EYE_THRESHOLD=0.25
EYES_CLOSED_DURATION=1
YAWNING_DURATION=3- Backend Connection Problems: Ensure Flask server is running and port is available.
- Camera Access Issues: Grant browser camera permissions, close other apps using the camera.
- Model Loading Errors: Check your internet connection or manually download the model.
- Performance Issues: Lower frame rate, close other apps, or reduce camera resolution.
- Enable debug mode in
.envor by runningapp.pywithdebug=True. - Check
app.logfor backend errors.
We welcome contributions! Please fork the repo, create a feature branch, and submit a pull request. See CONTRIBUTING.md for details.
This project is licensed under the MIT License - see the LICENSE file for details.
- MediaPipe Team: For the excellent facial landmark detection framework
- TensorFlow Community: For the deep learning infrastructure
- OpenCV Contributors: For computer vision capabilities
- Flask Development Team: For the lightweight web framework
For support, questions, or feature requests:
- GitHub Issues: Create an issue
- Documentation: Check this README and inline code comments
- Community: Join discussions in the GitHub repository