This project is designed to help prevent road accidents caused by driver drowsiness, especially for Lagos drivers who often spend long hours in traffic and risk feeling sleepy behind the wheel.
The system continuously monitors the driver's eyes using a webcam feed. By applying computer vision techniques, it can detect when the driver starts to close their eyes for too long, a key sign of drowsiness, and then triggers an alarm to alert the driver before an accident happens.
- Real-time Video Processing: Captures and analyzes webcam feed at 10 FPS
- WebSocket Communication: Bidirectional communication between frontend and backend
- Computer Vision Detection: Uses MediaPipe Face Mesh for accurate facial landmark detection
- Eye Aspect Ratio (EAR) Analysis: Calculates EAR to determine drowsiness levels
- Responsive UI: Modern Next.js frontend with real-time status updates
- Cross-platform: Works on Windows, macOS, and Linux
- Framework: FastAPI with WebSocket support
- Computer Vision: OpenCV + MediaPipe for face and eye detection
- Real-time Processing: Processes video frames and sends status updates
- CORS Enabled: Allows frontend communication
- Framework: Next.js 14 with TypeScript
- UI Components: Shadcn/ui for modern interface
- Real-time Updates: WebSocket integration for live status
- Video Capture: HTML5 Canvas for frame extraction
- Your webcam captures video of your face in real time
- forntend Sends webcam frames to the backend every 50ms
- MediaPipe detects landmarks around your eyes (like eyelids and corners)
- The backend calculates the Eye Aspect Ratio (EAR), a simple number that shows how open or closed your eyes are
- If EAR stays below a threshold for a few frames, the system flags drowsiness
- The backend sends the status to the frontend over WebSockets
- The frontend updates the UI and plays an alarm
- Python 3.8+
- Node.js 18+
- Webcam access
cd backend
pip install -r requirements.txt
uvicorn main:app --reloadcd frontend
npm install
npm run dev- Start the backend server (runs on http://localhost:8000)
- Start the frontend server (runs on http://localhost:3000)
- Open http://localhost:3000 in your browser
- Click "Start Camera" to begin monitoring
You can test the app here: Sleep Detection Live
Adjust the sleep detection sensitivity in backend/main.py:
EAR_THRESHOLD = 0.25 # Lower = more sensitiveModify capture settings in frontend/app/page.tsx:
const captureInterval = 100; // ms (10 FPS)
const quality = 0.8; // JPEG quality- Backend: FastAPI, OpenCV, MediaPipe, NumPy
- Frontend: Next.js, TypeScript, Tailwind CSS, Shadcn/ui
- Communication: WebSockets
- Computer Vision: Face detection, landmark tracking, EAR calculation
- Reduce latency for faster real-time updates on the live app
- Mobile app version
- Cloud deployment
- Advanced drowsiness detection algorithms
- Integration with vehicle systems
- improved UI