https://github.com/byigitt/no-sleep
Real-time drowsiness detection system using webcam eye tracking. Monitors Eye Aspect Ratio (EAR) via MediaPipe and triggers an alarm when eyes stay closed for too long.
https://github.com/byigitt/no-sleep
computer-vision driver-safety drowsiness-detection eye-tracking face-detection mediapipe opencv python safety webcam
Last synced: 3 months ago
JSON representation
Real-time drowsiness detection system using webcam eye tracking. Monitors Eye Aspect Ratio (EAR) via MediaPipe and triggers an alarm when eyes stay closed for too long.
- Host: GitHub
- URL: https://github.com/byigitt/no-sleep
- Owner: byigitt
- Created: 2026-01-24T18:22:26.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2026-01-24T18:32:16.000Z (5 months ago)
- Last Synced: 2026-03-01T19:47:39.031Z (4 months ago)
- Topics: computer-vision, driver-safety, drowsiness-detection, eye-tracking, face-detection, mediapipe, opencv, python, safety, webcam
- Language: Python
- Size: 3.17 MB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# No Sleep
Drowsiness detection system that monitors your eyes via webcam and triggers an alarm if you fall asleep.
## How It Works
1. Captures video from your webcam
2. Uses MediaPipe Face Landmarker to detect 478 facial landmarks
3. Calculates Eye Aspect Ratio (EAR) from 6 points per eye
4. When EAR drops below threshold (eyes closed) for >2 seconds, alarm beeps repeatedly
5. Alarm stops when you open your eyes
## Requirements
- Python 3.10+
- Webcam
- Windows (uses `winsound` for alarm)
## Installation
```bash
uv sync
```
The face landmarker model (~4MB) downloads automatically on first run.
## Usage
```bash
uv run main.py
```
Press `q` to quit.
## Status Indicators
| Color | Status | Meaning |
|-------|--------|---------|
| Green | Awake | Eyes open, all good |
| Orange | Eyes Closed (Xs) | Eyes closing, timer counting |
| Red | DROWSY! | Eyes closed >2s, alarm active |
| Gray | No Face Detected | Camera can't see your face |
## Configuration
Edit these values at the top of `main.py`:
| Variable | Default | Description |
|----------|---------|-------------|
| `EAR_THRESHOLD` | 0.2 | Eye aspect ratio threshold. Lower = more sensitive |
| `CLOSED_DURATION_THRESHOLD` | 2.0 | Seconds before alarm triggers |
| `ALARM_FREQUENCY` | 2500 | Beep frequency in Hz |
| `ALARM_DURATION` | 500 | Beep duration in ms |
## How EAR Works
Eye Aspect Ratio measures how "open" your eyes are:
```
EAR = (|p2-p6| + |p3-p5|) / (2 * |p1-p4|)
p2 p3
p1 p4
p6 p5
```
- Eyes open: EAR ≈ 0.25-0.35
- Eyes closed: EAR < 0.2