INNOVATIVE DRUNK PREVENTATION PROJECT
This project is a real-time pupil detection system that calculates the circumference of a person's pupils using OpenCV and Dlib. The system captures live video, detects facial landmarks, and measures the pupil circumference in millimeters. The data is stored in a CSV file for analysis.
- Real-time pupil detection using OpenCV and Dlib.
- Accurate pupil circumference measurement in millimeters.
- Live visualization of detected pupils and their measurements.
- Data logging in a CSV file for further analysis.
- Automatic frame capturing at a set frequency.
- Python 3.x
- OpenCV (
cv2) - Dlib (
dlib) - NumPy (
numpy)
-
Install dependencies:
pip install opencv-python dlib numpy
-
Download Dlib’s facial landmark model:
- Download
shape_predictor_68_face_landmarks.datfrom Dlib Model. - Extract it and place it in the same folder as the script.
- Download
-
Run the program:
python pupil_detection.py
- Captures live video from the webcam.
- Detects a face and extracts eye landmarks.
- Calculates pupil diameter and converts it to circumference using a fixed pixel-to-mm ratio.
- Displays the measurements in real-time.
- Saves data periodically in
pupil_data.csv.
The system logs the following information in pupil_data.csv:
| Left_Pupil_Circumference_mm | Right_Pupil_Circumference_mm |
|---|---|
| 1.45 mm | 1.67 mm |
| 2.23 mm | 2.45 mm |
- Adjust the frame capture frequency:
write_frequency = 10 # Captures data every 10 frames
- Change the pixel-to-mm ratio (based on camera calibration):
pixels_per_mm = 15
- Medical Analysis: Detect neurological issues based on pupil size.
- Driver Monitoring: Measure pupil dilation in drowsiness or impairment detection.
- Cognitive Research: Track focus and cognitive load based on pupil dilation.