You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This project implements a **Drowsiness Detection System**using **Computer Vision** and **Deep Learning** techniques to monitor and detect signs of drowsiness in drivers. The system tracks the driver's eye state and gaze direction using the webcam, and it raises an alert if drowsiness is detected, ensuring safer driving conditions.
3
+
> **Note:**This README is for the `logfeature` branch which includes additional terminal output for facial landmarks detection.
4
4
5
-
## Features
5
+
This project implements a **Drowsiness Detection System** using **Computer Vision** and **Deep Learning** techniques to monitor and detect signs of drowsiness in drivers. The system uses webcam input to track eye states, gaze direction, and facial landmarks, raising alerts when signs of drowsiness are detected.
6
+
7
+
## New Features in This Branch
6
8
7
-
-**Real-time Drowsiness Detection:** Tracks the eye state to detect when the driver is drowsy or blinking excessively.
8
-
-**Gaze Direction Tracking:** Monitors the direction of the gaze to determine if the driver is distracted.
9
-
-**Head Pose Estimation:** Analyzes the orientation of the driver's head to detect abnormal head movements or drowsiness.
10
-
-**Alert System:** Plays an alarm sound when drowsiness or distraction is detected.
11
-
-**Face and Eye Detection:** Utilizes Haar cascades for detecting faces and eyes.
9
+
-**Real-time Landmark Printing:** Continuously prints coordinates in terminal for:
10
+
- Left eye landmarks
11
+
- Right eye landmarks
12
+
- Complete facial landmarks (x, y, z coordinates)
13
+
- All other features from the main branch remain unchanged
14
+
15
+
## Features
12
16
17
+
-**Real-time Eye State Monitoring:** Uses a CNN model to classify eyes as open or closed
18
+
-**Drowsiness Score System:** Maintains a drowsiness score based on eye state patterns
19
+
-**Gaze Direction Tracking:** Uses MediaPipe face mesh to monitor the driver's gaze direction
20
+
-**Alert System:** Plays an alarm sound when prolonged drowsiness is detected
21
+
-**Event Logging:** Records drowsiness events with timestamps
22
+
-**Image Capture:** Saves images when drowsy or sleepy states are detected
23
+
-**Visual Indicators:** Dynamic visual overlays indicating different drowsiness levels
pip install protobuf==3.20.0# Required for MediaPipe compatibility
42
62
```
43
63
44
-
### 2. Using Conda Environment
64
+
### 3. Using Conda Environment
45
65
46
-
#### 2.1 Create Conda Environment
66
+
#### 3.1 Create Conda Environment
47
67
```bash
48
68
conda create --name drowsiness_env python=3.9 -y
49
69
```
50
70
51
-
#### 2.2 Activate Conda Environment
71
+
#### 3.2 Activate Conda Environment
52
72
```bash
53
73
conda activate drowsiness_env
54
74
```
55
75
56
-
#### 2.3 Install Dependencies
76
+
#### 3.3 Install Dependencies
57
77
```bash
78
+
pip install --upgrade pip
58
79
pip install -r requirements.txt
59
-
pip install protobuf==3.20.0
80
+
pip install protobuf==3.20.0# Required for MediaPipe compatibility
60
81
```
61
82
62
-
### 3. Verify Setup
63
-
64
-
Check installed packages:
83
+
### 4. Verify Installation
65
84
```bash
66
-
pip list
67
-
```
68
-
69
-
## Recommendations
70
-
71
-
-**Conda is recommended** for managing complex dependencies, especially for machine learning projects with potential GPU support.
72
-
- Always ensure you're in the correct virtual environment before running the project.
73
-
- Keep your `requirements.txt` updated with all necessary dependencies.
74
-
75
-
## Troubleshooting
76
-
77
-
- If you encounter any installation issues, ensure you have the latest version of pip:
78
-
```bash
79
-
pip install --upgrade pip
80
-
```
81
-
- Check Python version compatibility (Python 3.7 - 3.9 recommended)
82
-
- Verify all system dependencies are installed
83
-
84
-
Required libraries include:
85
-
```text
86
-
opencv-python
87
-
mediapipe
88
-
numpy
89
-
keras
90
-
pygame
85
+
pip list # Check installed packages
91
86
```
92
87
93
-
### 4. Model and Haar Cascade Files
94
-
Ensure the following files are available in the project directory:
88
+
### 5. Required Files
95
89
96
-
Pre-trained model for eye state classification:
97
-
-`cnnfinal.h5`
90
+
The system needs the following files in the project directory:
98
91
99
-
Haar cascade files for face and eye detection:
100
-
-`haarcascade_frontalface_alt.xml`
101
-
-`haarcascade_lefteye_2splits.xml`
102
-
-`haarcascade_righteye_2splits.xml`
92
+
1.**Model File:**
93
+
-`cnnfinal.h5` (Pre-trained CNN model for eye state classification)
103
94
104
-
These files can be downloaded from the official OpenCV repository or extracted from your local OpenCV installation.
95
+
2.**Haar Cascade Files:**
96
+
- OpenCV's pre-trained Haar cascade files (automatically accessed via cv2.data.haarcascades)
105
97
106
-
### 5. Alarm Sound
107
-
Place an `alarm.wav` file in the project directory. This sound will be played when the system detects drowsiness or distraction.
98
+
3.**Audio File:**
99
+
-`alarm.wav`(Sound file for drowsiness alerts)
108
100
109
101
## Usage
110
102
111
-
### 1. Running the Script
112
-
To start the drowsiness detection system, run:
103
+
### Running the System
104
+
105
+
1. Start the program:
113
106
```bash
114
-
python test.py
107
+
python drowdlog.py
115
108
```
116
-
This will open the webcam feed and start tracking the driver's eye state, gaze direction, and head pose in real-time.
117
-
118
-
### 2. How It Works
119
-
-**Eye State Detection**: The system uses a Convolutional Neural Network (CNN) to classify whether the driver's eyes are open or closed.
120
-
-**Face and Eye Detection**: Haar cascades are used to detect the driver's face and eyes. The system tracks the eye region to monitor blinking and drowsiness.
121
-
-**Gaze Direction Tracking**: Using MediaPipe, the system estimates the gaze direction to detect whether the driver is distracted or looking away from the road.
122
-
-**Head Pose Estimation**: The system tracks the head's orientation to determine if the driver is nodding or tilting their head abnormally.
123
-
-**Alert System**: If drowsiness is detected (closed eyes for a certain duration or excessive blinking), an alarm sound is played.
124
-
125
-
### 3. Exiting the Program
126
-
To exit the program, press `q` in the terminal or stop the script execution.
When running the system, you'll see continuous output in the terminal showing:
127
+
- Face landmark coordinates (x, y, z)
128
+
- Left and right eye bounding box coordinates
129
+
- Detection status and changes
130
+
131
+
This feature is useful for:
132
+
- Debugging landmark detection
133
+
- Validating eye tracking accuracy
134
+
- Development and testing of new features
129
135
130
136
## Troubleshooting
131
137
132
-
-**Webcam not detected**: Ensure that your webcam is properly connected and accessible by other applications. Try restarting your machine if the issue persists.
133
-
-**Model loading errors**: If you get an error related to loading the model (`cnnfinal.h5`), make sure the file is placed in the correct directory and the path is specified correctly in the script.
138
+
Common issues and solutions:
134
139
135
-
## Reporting Issues and Contributing
140
+
1. **Webcam Not Detected:**
141
+
- Check webcam connection
142
+
- Verify webcam permissions
143
+
- Try different video capture device indices
136
144
137
-
### Reporting Errors or Bugs
145
+
2. **Model Loading Errors:**
146
+
- Ensure `cnnfinal.h5` is in the correct directory
147
+
- Verify Keras version compatibility
138
148
139
-
1.**Check Existing Issues**
140
-
- Before reporting, search existing GitHub issues to avoid duplicates.
149
+
3. **MediaPipe Errors:**
150
+
- Check Python version compatibility
151
+
- Verify MediaPipe installation
141
152
142
-
2.**Create a Detailed Bug Report**
143
-
- Use GitHub Issues
144
-
- Include:
145
-
- Detailed description of the error
146
-
- Steps to reproduce
147
-
- Your environment details (OS, Python version, etc.)
148
-
- Full error traceback
149
-
150
-
151
-
- Discuss in project discussions/comments
153
+
4. **Terminal Output Issues:**
154
+
- If landmark coordinates aren't printing, check if MediaPipe face mesh initialization is successful
155
+
- Verify console/terminal has sufficient scroll buffer for continuous output
152
156
153
157
## Contributing
154
158
155
-
We welcome contributions to this project! If you'd like to contribute, please follow these steps:
156
-
157
-
1. Fork the repository.
158
-
2. Create a new branch for your changes.
159
-
3. Commit your changes.
160
-
4. Push your changes and create a pull request.
159
+
Contributions are welcome! Please feel free to submit pull requests or report issues.
161
160
162
161
## License
163
162
164
-
This project is licensed under the MIT License - see the LICENSE file for details.
163
+
This project is licensed under the MIT License.
165
164
166
165
## Acknowledgments
167
166
168
-
-**OpenCV**: For providing the face and eye detection algorithms.
169
-
-**MediaPipe**: For real-time gaze and head pose tracking.
170
-
-**Keras**: For providing the deep learning framework used to train the eye state classification model.
0 commit comments