Welcome to the Eye Blink Detection repository! This project utilizes OpenCV and MediaPipe to detect eye blinks in real-time using a webcam. It calculates the Eye Aspect Ratio (EAR) to determine whether the eyes are open or closed, and displays the last blink time on the screen.
- Real-Time Eye Blink Detection: Detects blinks in real-time using webcam input.
- Eye Aspect Ratio Calculation: Uses EAR to determine eye state.
- Blink Timestamp: Displays the last blink time on the screen.
- Simple and Intuitive Interface: Easy-to-understand visual cues for eye state.
-
Clone the Repository:
git clone https://github.com/fastuptime/Eye_Blink_Detection.git cd Eye_Blink_Detection
-
Install Dependencies:
- Ensure you have Python installed.
- Install required packages:
pip install opencv-python mediapipe numpy
-
Run the Program:
- Execute the Python script:
python eye_blink_detection.py
- Execute the Python script:
-
Launch the Program:
- Run the script. The webcam will start, and the program will begin detecting blinks.
-
Eye Blink Detection:
- The program displays the current state of the eyes (open or closed) on the screen.
- It also shows the last blink time.
-
Exit the Program:
- Press the 'q' key to quit the program.
-
Import Libraries:
import cv2 import mediapipe as mp import numpy as np import time
-
Initialize MediaPipe and OpenCV:
mp_face_mesh = mp.solutions.face_mesh mp_drawing = mp.solutions.drawing_utils face_mesh = mp_face_mesh.FaceMesh(min_detection_confidence=0.5, min_tracking_confidence=0.5)
-
Calculate Eye Aspect Ratio (EAR):
def eye_aspect_ratio(landmarks, eye_indices): # Implementation to calculate EAR
-
Threshold for Eye Aspect Ratio:
EYE_AR_THRESH = 0.3
-
Capture Video from Webcam:
cap = cv2.VideoCapture(0) lastTime = 'Bilinmiyor'
-
Main Loop for Eye Blink Detection:
while cap.isOpened(): ret, frame = cap.read() if not ret: break # Implementation for processing frame and detecting blinks
-
Display Results and Handle Exit:
cv2.imshow('Goz Kirpma Tespiti', frame) if cv2.waitKey(1) & 0xFF == ord('q'): break cap.release() cv2.destroyAllWindows()
Contributions are welcome! Feel free to open issues or submit pull requests.
- Fork the repository.
- Create a new branch (
git checkout -b feature-branch
). - Commit your changes (
git commit -am 'Add new feature'
). - Push to the branch (
git push origin feature-branch
). - Open a pull request.