This project detects and visualizes the direction of a person's gaze in real-time using a webcam.
- Real-time gaze direction detection: Classifies gaze as Left, Right, Up, Down, Center, or combinations (e.g., Up-Left).
- Visual feedback: Draws arrows from the iris centers indicating gaze direction, and overlays text on the video feed.
- Smoothing: Uses a short history of predictions to stabilize the output and reduce flicker.
- Robust iris tracking: Uses MediaPipe’s refined landmarks for accurate iris localization.
-
Face & Iris Detection:
MediaPipe FaceMesh detects facial landmarks, including iris positions. -
Gaze Estimation:
The code calculates the relative position of each iris within its eye using landmark ratios.- Horizontal and vertical ratios are computed for both eyes.
- These ratios are classified into gaze directions (Left, Right, Up, Down, Center).
-
Smoothing:
A short history of gaze predictions is kept. The most frequent recent prediction is used for display. -
Visualization:
- Arrows are drawn from each iris center in the direction of the detected gaze.
- The current gaze direction is displayed as text.
- Python 3.7+
- OpenCV (
opencv-python) - MediaPipe (
mediapipe)
Install dependencies:
pip install opencv-python mediapipeRun the application:
python app.py- A window will open showing the webcam feed.
- Gaze direction is indicated by arrows and text.
- Press
ESCto exit.
Gaze-Detection/
├── app.py # Main application code
├── README.md # Project documentation
- Smoothing window:
Changegaze_history = deque(maxlen=10)for more/less smoothing. - Arrow length:
Adjustlengthindraw_arrow()for longer/shorter arrows. - Gaze thresholds:
Modify values inget_gaze_direction()for sensitivity tuning.