Skip to main content

Webcam-based eye-tracking

Project description

EyePy

made-with-python Open Source Love License: MIT GitHub stars

Demo

EyePy is a Python library that provides webcam-based eye tracking. Extract facial features, train eye tracking model and predict gaze with super easy to use interface.

The repo also includes a virtual camera script allowing integration with streaming software like OBS.

Installation

Clone this project:

git clone https://github.com/ck-zhang/EyePy

Using Pip

python -m venv venv
source venv/bin/activate  # On Windows use: venv\Scripts\activate
pip install -r requirements.txt

Using uv

# Install uv https://github.com/astral-sh/uv/?tab=readme-ov-file#installation
pip install uv
uv sync
source venv/bin/activate  # On Windows use: venv\Scripts\activate

Demo

To run the gaze estimation demo:

python demo.py [OPTIONS]

Options

Option Description Default
--filter Filter method (kalman, kde, none) none
--camera Index of the camera to use 0
--calibration Calibration method (9p, 5p, lissajous) 9p
--background Path to background image None
--confidence Confidence interval for KDE contours (0 to 1) 0.5

Virtual Camera Script (only tested on linux)

python virtual_cam.py [OPTIONS]

Virtual Camera Options

Option Description Default
--filter Filter method (kalman, kde, none) none
--camera Index of the camera to use 0
--calibration Calibration method (9p, 5p, lissajous) 9p
--confidence Confidence interval for KDE contours (0 to 1) 0.5

Virtual camera demo

https://github.com/user-attachments/assets/7337f28c-6ce6-4252-981a-db77db5509f6

Usage as library

Initialization

from EyePy import GazeEstimator
gaze_estimator = GazeEstimator()

Feature Extraction

import cv2
image = cv2.imread('image.jpg')
features, blink_detected = gaze_estimator.extract_features(image)

if features is None:
    print("No face detected.")
elif blink_detected:
    print("Blink detected!")
else:
    print("Extracted features:", features)

Training the Model

X = [[...], [...], ...]  # Each element is a feature vector
y = [[x1, y1], [x2, y2], ...]  # Corresponding gaze coordinates
gaze_estimator.train(X, y)

Predicting Gaze Location

predicted_gaze = gaze_estimator.predict([features])
print("Predicted gaze coordinates:", predicted_gaze[0])

Future Work

TODO

  • Virtual camera script Integrate with OBS
  • Integrate with opentrack

Any suggestions for features and improvements are welcome.

If you enjoyed using EyePy, consider giving it a star.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

eyetrax-0.2.1.tar.gz (3.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

eyetrax-0.2.1-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file eyetrax-0.2.1.tar.gz.

File metadata

  • Download URL: eyetrax-0.2.1.tar.gz
  • Upload date:
  • Size: 3.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.20

File hashes

Hashes for eyetrax-0.2.1.tar.gz
Algorithm Hash digest
SHA256 7590be0994f38eda44927d8fa22738c08dad2b9c3baa04c390613dfb382ecd09
MD5 3c40704afd310a2b540c5bc5c05be281
BLAKE2b-256 ab1643a903af2e91cf6e8f3b891ebdf2720298fe6f74698524d9a463b1ceb319

See more details on using hashes here.

File details

Details for the file eyetrax-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: eyetrax-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.20

File hashes

Hashes for eyetrax-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b4931be01b5bd41f3e4c20eba2b6b49527415d124a9289e20c3b9c27da1b7e71
MD5 d971af9f92d2d2ba95fec493781430df
BLAKE2b-256 fa830baad0a3eb565fa346f5c5624403250bfd0e33086a609e64449d7970da46

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page