Skip to content

getankushtyagi/eye-close-detector-

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

😴 Driver Drowsiness Detection (No YOLO)

A real-time driver drowsiness detection system built using OpenCV + MediaPipe, without using YOLO or any deep-learning object detector.

This project focuses on understanding AI system design, combining computer vision, geometry, and time-based logic instead of training heavy models.


📌 Project Objective

To detect driver drowsiness by monitoring eye closure over time using facial landmarks.

Core rule:
If the driver's eyes remain closed for more than a fixed duration → trigger an alert.


🧠 Why This Project Is Important

This project teaches real-world AI concepts:

  • AI does NOT always mean deep learning
  • Feature engineering can replace training
  • Geometry + logic = reliable systems
  • Time-based reasoning avoids false alarms
  • Explainable AI (easy to understand & debug)

This approach is commonly used in:

  • Automotive safety systems
  • Fleet monitoring
  • Driver assistance systems

🚀 Features

✅ Real-time webcam processing
✅ Face and eye landmark detection
✅ Eye Aspect Ratio (EAR) calculation
✅ Time-based drowsiness detection
✅ Visual alert on screen
✅ Optional sound alert (macOS)
✅ No dataset required
✅ No model training required
✅ Runs fully offline on CPU


🛠️ Technology Stack

  • Python 3.9+
  • OpenCV – video capture & visualization
  • MediaPipe Face Mesh – facial landmarks
  • NumPy – numerical operations
  • SciPy – distance calculations
  • Time module – duration tracking

❌ No YOLO
❌ No deep learning training
❌ No GPU required


🧩 How It Works (High-Level)

Webcam Frame
   ↓
Face Detection (MediaPipe)
   ↓
Eye Landmark Extraction
   ↓
Eye Aspect Ratio (EAR)
   ↓
Time-based Logic
   ↓
DROWSINESS ALERT

🔢 Core Concept – Eye Aspect Ratio (EAR)

EAR measures how open an eye is using landmark distances.

EAR = (vertical distances) / (horizontal distance)
  • Eye open → EAR ≈ 0.30
  • Eye closed → EAR ≈ 0.15

If EAR drops below a threshold for enough time, drowsiness is detected.


📁 Project Structure

drowny/
├── drowsiness_detection.py   # Main application file
├── venv/                     # Python virtual environment
└── README.md                 # Project documentation

⚙️ Installation & Setup

1️⃣ Create virtual environment

python3 -m venv venv
source venv/bin/activate

2️⃣ Install dependencies

pip install opencv-python mediapipe numpy scipy

⚠️ Recommended MediaPipe version:

pip install mediapipe==0.10.8

▶️ Run the Project

python3 drowsiness_detection.py

Controls

  • Press q to quit

🎯 Configuration Parameters

Inside drowsiness_detection.py:

EAR_THRESHOLD = 0.25   # Eye closed threshold
DROWSY_TIME = 2.0      # Seconds eyes must stay closed

Tuning tips:

  • Lower EAR_THRESHOLD → more sensitive
  • Lower DROWSY_TIME → faster alerts

🧠 Key Learnings from This Project

  • Blinking ≠ drowsiness
  • Time-based logic is critical
  • Geometry can replace deep learning
  • AI systems need rules, not just predictions
  • Debugging environments is part of AI work

🚫 Limitations

  • Works best for frontal faces
  • Single-person detection
  • Glasses may affect accuracy
  • No head-pose compensation (future improvement)

🔮 Possible Enhancements

  • Sound alarm using audio file
  • Head pose estimation
  • Multiple face handling
  • Event logging to file
  • Mobile / edge deployment
  • Combine with deep learning later

🧪 Real-World Applications

  • Driver safety systems
  • Fleet monitoring
  • Long-haul transport safety
  • Automotive research
  • AI learning & demos

📜 License

This project is for educational and learning purposes. Use responsibly in real-world safety systems with proper testing.


🙌 Final Note

This project proves that:

Good AI is about understanding the problem, not just using big models.

You now understand AI system design, not just AI tools.


Happy coding! 🚗💤

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages