This guide will walk you through setting up the Driver Monitoring System from scratch.
- System Requirements
- Python Installation
- Project Setup
- Model Setup
- Alert System Configuration
- Running the Application
- Troubleshooting
- OS: Windows 10, macOS 10.15+, or Linux (Ubuntu 18.04+)
- RAM: 4 GB (8 GB recommended)
- Python: 3.8 or higher
- Webcam: Any USB or built-in camera
- Internet: Required for WhatsApp alerts
- RAM: 8 GB or more
- GPU: NVIDIA GPU with CUDA support (optional, for faster processing)
- Python: 3.9 or 3.10
- Download Python from python.org
- Run the installer
- ✅ Important: Check "Add Python to PATH"
- Verify installation:
python --version
- Install Homebrew (if not already installed):
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" - Install Python:
brew install python@3.10
- Verify installation:
python3 --version
sudo apt update
sudo apt install python3 python3-pip python3-venv
python3 --versiongit clone https://github.com/yourusername/Driver_Monitoring_System.git
cd Driver_Monitoring_SystemWindows:
python -m venv venv
venv\Scripts\activatemacOS/Linux:
python3 -m venv venv
source venv/bin/activateYou should see (venv) in your terminal prompt.
pip install --upgrade pip
pip install -r requirements.txtThis may take 5-10 minutes depending on your internet connection.
python -c "import cv2, flask, ultralytics; print('All packages installed successfully!')"-
YOLOv8 Nano (General Object Detection)
# This will auto-download on first run # Or manually download from: https://github.com/ultralytics/ultralytics
-
Face Mask Model (
best.pt)- Train your own using
train.ipynb - Or request from project maintainer
- Train your own using
-
Hand Detection Model (
handdsa.pt)- Train your own or use a pre-trained hand detection model
-
Smoking Detection Model (
detection_module.pt)- Optional - train if needed
-
Open
train.ipynbin Jupyter:pip install jupyter jupyter notebook train.ipynb
-
Follow the notebook instructions to:
- Prepare your dataset
- Configure training parameters
- Train the model
- Export the
.ptfile
-
Place trained models in the
models/directory
models/
├── best.pt # Mask detection
├── yolov8n.pt # General detection
├── handdsa.pt # Hand detection
└── detection_module.pt # Smoking detection (optional)
- Go to cloudinary.com
- Sign up for a free account
- Navigate to Dashboard
- Note your:
- Cloud Name
- API Key
- API Secret
- Go to twilio.com
- Sign up for a free trial account
- Navigate to Console Dashboard
- Note your:
- Account SID
- Auth Token
- In Twilio Console, go to Messaging → Try it out → Send a WhatsApp message
- Follow instructions to join the sandbox (send a code to the Twilio number)
- Note the WhatsApp Sandbox Number:
whatsapp:+14155238886
-
Copy the template:
cp alert_system_template.py alert_system.py
-
Edit
alert_system.pywith your credentials:CLOUDINARY_NAME = "your_cloud_name" CLOUDINARY_KEY = "your_api_key" CLOUDINARY_SECRET = "your_api_secret" TWILIO_SID = "your_account_sid" TWILIO_TOKEN = "your_auth_token" TWILIO_FROM_NUMBER = "whatsapp:+14155238886" YOUR_WHATSAPP_NUMBER = "whatsapp:+1234567890" # Your number
from alert_system import configure_alerts, send_whatsapp_alert
configure_alerts()
send_whatsapp_alert("Test message from Driver Monitoring System!")python app.pyYou should see:
Loading YOLO models...
Models loaded successfully.
✅ Alert system configured (Cloudinary & Twilio).
* Running on http://127.0.0.1:5000
- Open your browser
- Navigate to:
http://localhost:5000 - Allow camera access when prompted
Live Mode:
- Click "Start Camera"
- Position yourself in front of the camera
- Test different scenarios:
- Close your eyes for 2+ seconds (drowsiness)
- Hold a phone to your ear
- Cover your face with your hand
Image Upload Mode:
- Click "Image Upload" tab
- Upload a test image
- View detection results
ModuleNotFoundError: No module named 'cv2'
Solution:
pip install opencv-python-headlessCannot access camera
Solutions:
- Check camera permissions in system settings
- Close other apps using the camera
- Try a different browser (Chrome recommended)
FileNotFoundError: models/best.pt not found
Solution:
- Ensure models are in the
models/directory - Check file names match exactly
Solution:
# In app.py, reduce batch size or use CPU
device = 'cpu' # Instead of 'cuda'TwilioRestException: Unable to create record
Solutions:
- Verify credentials are correct
- Check Twilio trial account limits
- Ensure you've joined the WhatsApp sandbox
Address already in use
Solution:
# Use a different port
python app.py --port 8080Or kill the process using port 5000:
Windows:
netstat -ano | findstr :5000
taskkill /PID <PID> /FmacOS/Linux:
lsof -ti:5000 | xargs kill -9-
Reduce frame processing:
DETECT_HEAVY_EVERY_N = 5 # Process every 5th frame
-
Lower image resolution:
imgsz = 416 # Instead of 640
-
Use smaller model:
- YOLOv8n (nano) is fastest
- YOLOv8s (small) for better accuracy
- Enable GPU if available
- Increase
DETECT_HEAVY_EVERY_N - Close other applications
If you're still stuck:
- Check existing issues: GitHub Issues
- Create new issue: Provide:
- Error message
- Operating system
- Python version
- Steps to reproduce
- Email: your.email@example.com
Once everything is working:
- ✅ Test all detection modules
- ✅ Customize thresholds in
app.py - ✅ Train custom models for better accuracy
- ✅ Set up proper environment variables for production
- ✅ Consider deploying to cloud (AWS, GCP, Azure)
- Move credentials to environment variables
- Enable HTTPS
- Set up proper logging
- Implement rate limiting
- Add authentication
- Use production WSGI server (gunicorn, uWSGI)
# Install gunicorn
pip install gunicorn
# Run with gunicorn
gunicorn -w 4 -b 0.0.0.0:8000 app:appCongratulations! Your Driver Monitoring System is now set up and running! 🎉