How dilatuanaucar/drowsiness-detection works
Project Type and Purpose
• This is a standalone Python computer-vision application for real-time drowsiness detection. It uses OpenCV to capture frames from a webcam, Haar cascades to locate faces and eyes, and a pre-trained Keras CNN to classify eye state. When eyes remain closed beyond a threshold, it triggers an audio alert.
Key Components (to appear
a. Input Layer
• Webcam (live video feed)
b. Preprocessing & Detection
• Frame Grabber (OpenCV VideoCapture)
• Face Detector (haar cascade: haarcascade_frontalface_alt.xml)
• Eye Detectors (haar cascade: lefteye & righteye .xml)
• ROI Extractor & Preprocessor (crop, grayscale, resize)
c. Classification Engine
• CNN Model Loader (loads models/cnnCat2.h5 via model.py)
• Inference Module (Keras/TensorFlow calls to classify “Open” vs “Closed”)
d. Logic & Scoring
• Score Calculator (maintains drowsiness score, increments when “Closed”)
• Threshold Checker (evaluates when score > limit)
e. Alert System
• Audio Player (plays alarm.wav when drowsiness detected)
f. File System Dependencies
• haar cascade .xml files (stored under “haar cascade files”)
• Model file (models/cnnCat2.h5)
• Python scripts (model.py for training, drowsiness detection.py as main)
Relationships and Data Flow
Webcam → Frame Grabber → Face Detector → Eye Detectors → ROI Extractor → Classification Engine → Logic & Scoring → Alert System
• That Detection modules share data with Preprocessor and feed into the CNN.
Architectural Patterns & Design Principles
• Pipeline pattern: each stage performs one responsibility (capture → detect → classify → alert).
• Separation of concerns:
• model.py handles model creation/training
• drowsiness detection.py orchestrates capture, inference, scoring, alert
• Local storage of static assets (cascades + .h5 model) vs. runtime modules.