GazeTracking: webcam eye tracking in Python with OpenCV and dlib
👀 Eye Tracking library easily implementable to your projects
At a glance
- What is it?
- GazeTracking is a small Python library that turns a single webcam frame into pupil coordinates and left/center/right gaze flags. It is aimed at developers who want gaze input inside their own loop, not at researchers who need calibrated measurements.
- Who is it for?
- GazeTracking fits developers who want a rough gaze signal inside an existing Python and OpenCV loop: webcam games, attention toys, accessibility demos, or a first pass before committing to a heavier toolkit. It does not fit anyone who needs measured accuracy, head-pose compensation, or a supported release, because there is no versioned release and no calibration step in the README.
- Can I use it commercially?
- Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Activity is slowing. The repository last received commits 6 months ago.
- What is it written in?
- Mainly Python, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on November 22, 2026, and from our analysis. They are not legal advice.
Star history
- antoinelame/GazeTracking2,651 ★ · +17
| Repository | 2026-10-04 | 2026-11-22 |
|---|---|---|
| antoinelame/GazeTracking | 2.6k | 2.7k |
17 Stars in the last 49 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
What GazeTracking actually returns
The library answers one narrow question: where are the pupils in this frame, and which way is the person looking? It exposes pupil coordinates for each eye, boolean flags for left, right and center, a horizontal and vertical ratio between 0.0 and 1.0, and an is_blinking check. The README describes it as a webcam-based eye tracking system that gives the exact position of the pupils and the gaze direction in real time.
The audience is developers, not researchers. The pyproject.toml classifier says Development Status :: 4 - Beta and Intended Audience :: Developers. If you need degrees of visual angle, a fixation filter, or a Tobii-comparable sampling rate, this is not that tool. If you need a Python object that tells you whether the user glanced left during a webcam loop, it is.
How the detection pipeline is put together
The repository layout is small: a single gaze_tracking package, example.py, and a trained_models directory shipped as package data. The pyproject.toml declares three runtime dependencies: dlib>=20.0, numpy>=2.0 and opencv-python>=4.10. That dependency list is the architecture in miniature. OpenCV supplies the frame and the drawing helpers, dlib supplies the facial landmark detector and the trained model files, and numpy carries the arrays between them.
The data flow in the README example is explicit. You capture a frame with cv2.VideoCapture(0), pass it to gaze.refresh(frame), then read derived values such as is_left() and pupil_left_coords(). The annotated_frame() method returns the same frame with pupils highlighted, which is how the demo draws its overlay. Nothing is asynchronous and nothing is buffered: refresh() analyzes the frame you hand it, so the caller owns the loop, the frame rate and the threading model. That is a deliberate simplification and it means the library cannot drop or interpolate frames on your behalf.
Installing GazeTracking and running a first loop
The README offers four install paths: pip, uv, conda, and Docker. The pip route is the standard one. Clone the repository, create a virtual environment, and install it in editable mode.
git clone https://github.com/antoinelame/GazeTracking.git
cd GazeTracking
python -m venv .venv
source .venv/bin/activate
pip install -e .On Windows the README gives .venv\Scripts\activate instead of the source line. Python 3.10 or newer is required, and the pyproject.toml classifiers list 3.10 through 3.13. The README notes that the dlib wheel usually installs fine, but if pip compiles it from source you need CMake first: brew install cmake on macOS, or sudo apt install cmake build-essential on Ubuntu.
If you prefer uv, the README gives uv venv followed by uv pip install -e . as a faster alternative. The conda path is conda env create --file environment.yml and conda activate GazeTracking. Docker is Linux only, because the container uses your webcam and display, and it runs through ./build_and_run.sh. The Dockerfile itself is based on python:3.12-slim, installs cmake, build-essential, libgl1 and libglib2.0-0, creates a non-root app user, and ends with CMD ["python", "example.py"].
Once installed, run the bundled demo with python example.py. To write your own loop, the README's minimal example is the template: construct GazeTracking(), open cv2.VideoCapture(0), and call refresh on each frame.
import cv2
from gaze_tracking import GazeTracking
gaze = GazeTracking()
webcam = cv2.VideoCapture(0)
while True:
_, frame = webcam.read()
gaze.refresh(frame)
new_frame = gaze.annotated_frame()
cv2.imshow("Demo", new_frame)
if cv2.waitKey(1) == 27:
breakThe window titled Demo should show your camera feed with the pupils marked. In the README's full example the same loop also reads gaze.is_right(), gaze.is_left() and gaze.is_center() and paints a text label at position (60, 60) with cv2.putText. Pressing Escape exits, because the loop breaks when cv2.waitKey(1) returns 27. The annotated_frame() call is what makes the pupils visible; without it you only get numbers.
No calibration, and what that costs you
There is no calibration step anywhere in the README. You do not show the user a set of dots and fit a mapping from pupil position to screen coordinates. Instead the ratio methods return a normalized value where 0.0 is one extreme, 0.5 is the center and 1.0 is the other. That design keeps the API small and the setup to one line, and it is also the biggest limitation.
Because the mapping is relative to the detected eye region rather than to the screen, it is sensitive to head pose and camera placement. Move the webcam, tilt your head, or sit off-axis and the ratio shifts even if your gaze does not. Nothing in the README documents a head-pose correction or a per-user baseline. There is also no accuracy figure, no frame-rate figure and no reported error margin, so anyone who needs a measurement rather than a direction signal should treat the output as a heuristic. The is_blinking check depends on the same landmark detection, so a missed detection can read as a blink or as a lost pupil. The README does not document what refresh() does when no face is found, and there is no rollback or fallback behaviour described.
Where the maintenance and upgrade story stands
The repository is not archived, and the last push was on 2026-04-27. The repository has no published GitHub releases, and the pyproject.toml still carries version 0.1.0 with a Beta classifier. In practice that means you install from the Git repository or from the editable install described above, not from a pinned version on PyPI that you can lock and audit. An upgrade is a git pull plus a reinstall, and because the package ships trained_models/*.dat as package data, a model file change arrives with the code change rather than as a separate artefact.
The licence is MIT, declared both in the LICENSE file and in the pyproject.toml license field. MIT is permissive: it allows commercial and closed-source use with attribution and the licence text retained. That is a statement about the licence terms, not legal advice, and the dlib, numpy and opencv-python dependencies carry their own licences that you should check separately if redistribution matters to you.
How it compares with WebGazer and MediaPipe routes
WebGazer is the closest alternative in the related searches, and the difference is the execution model. WebGazer runs in the browser and is written in JavaScript, so it fits a web page that wants gaze input without a server. GazeTracking runs in Python and hands you a numpy array, so it fits a desktop loop, a local script or a server-side pipeline that already has OpenCV. They are not interchangeable: choosing GazeTracking means your application is a Python process with webcam access, not a page in a tab.
The other route people search for is MediaPipe, which is a different detection stack rather than a drop-in replacement. GazeTracking's dependency list is dlib and OpenCV, and its trained models ship inside the package. Swapping the detector would mean rewriting the internals, not changing a flag. If dlib's build step is the thing blocking you, that is a reason to look at a MediaPipe-based implementation, not a configuration option inside this library.
Editorial conclusion
GazeTracking fits developers who want a rough gaze signal inside an existing Python and OpenCV loop: webcam games, attention toys, accessibility demos, or a first pass before committing to a heavier toolkit. It does not fit anyone who needs measured accuracy, head-pose compensation, or a supported release, because there is no versioned release and no calibration step in the README. Before adopting it, check that dlib builds in your environment (the README points to CMake when the wheel fails) and confirm that dlib's face landmark model is accurate on your camera and lighting, since the library has no fallback when landmark detection misses.
Frequently asked questions
What is GazeTracking and what does it return?
It is a Python 3.10+ library that provides a webcam-based eye tracking system. It returns pupil coordinates for each eye, left, right and center gaze flags, horizontal and vertical ratios between 0.0 and 1.0, and a blink check.
How do I install GazeTracking?
Clone the repository and install it in editable mode with a virtual environment, or use one of the three alternatives the README lists: uv, conda with environment.yml, or the Linux-only Docker script build_and_run.sh. Python 3.10 or newer is required.
Does GazeTracking need a calibration step?
No. The README documents no calibration procedure. The ratio methods return a normalized value where 0.0 is one extreme, 0.5 is the center and 1.0 is the other, which means the output is relative to the detected eye region rather than to your screen.
What happens if dlib fails to install?
The README says the wheel usually installs fine, but if pip tries to compile dlib from source you need CMake first: brew install cmake on macOS, or sudo apt install cmake build-essential on Ubuntu.
Can I run GazeTracking in Docker?
Yes, but the README states the Docker option is Linux only because it uses your webcam and display. The script is ./build_and_run.sh, and the Dockerfile ends by running python example.py.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/antoinelame-gazetracking)Star history chart for your README
[](https://hysenlabs.com/projects/antoinelame-gazetracking)Was this useful?