This project implements a real-time eye-tracking system using OpenCV and MediaPipe. The code tracks the user's eye position (left, right, or center) and displays it on the screen. The system works by detecting facial landmarks, extracting eye regions, and estimating the eye's position based on pixel analysis.
Eye_Tracking.py: Main script that captures video input, processes each frame to detect eyes, and estimates eye position. utils.py: Utility functions for drawing colored backgrounds and text on images.
- Real-Time Tracking: Detects eye landmarks using MediaPipe Face Mesh.
- Eye Region Extraction: Extracts and displays regions of interest from the eyes.
- Position Estimation: Classifies eye position (CENTER, LEFT, RIGHT) based on pupil location.
- Live Visualization: Displays eye tracking and position estimation on the video feed.
Ensure you have Python 3.x installed. The following packages are required:
- OpenCV
- MediaPipe
- NumPy
-
Clone the Repository:
git clone https://github.com/EsraaMeslam/-Real-Time-Eye-Tracking-and-Position-Estimation-Using-OpenCV-and-MediaPipe-.git cd Real-Time-Eye-Tracking-and-Position-Estimation-Using-OpenCV-and-MediaPipe -
Install Required Packages:
pip install -r requirements.txt
-
Prepare Your Video File:
Place your video file in the project directory and name it
eye.mp4. Alternatively, update thecv2.VideoCapture("eye.mp4")line inEye_Tracking.pywith the path to your video file. -
Run the Script:
python Eye_Tracking.py
-
View Results:
The application will open a window showing the real-time video feed with eye tracking and position estimation. Press
qto quit the application.
Eye_Tracking.py: Main script for eye tracking. Captures video, processes frames to detect facial landmarks, extracts eye regions, estimates eye position, and displays results.utils.py: Utility functions for text rendering and color management used in the eye tracking script.requirements.txt: Lists the required Python packages for the project.
- Real-Time Eye Tracking Window: Shows the original video with outlined eye regions and estimated eye position.
- Eye Region Windows: Displays cropped regions of the left and right eyes.
- Ensure that the video file is in a compatible format and accessible from the script.
- Adjust script parameters as needed for better accuracy or different video resolutions.
- MediaPipe: For providing a powerful library for facial landmark detection.
- OpenCV: For its robust image processing capabilities.