[go: up one dir, main page]

Skip to content

👀 Eye Tracking library easily implementable to your projects

License

Notifications You must be signed in to change notification settings

AmmarRashed/GazeTracking

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gaze Tracking

made-with-python Open Source Love License: MIT

This is a Python (2 and 3) library that provides a webcam-based eye tracking system. It gives you the exact position of the pupils and the gaze's direction, in real time.

Demo

Installation

Clone this project:

git clone https://github.com/antoinelame/GazeTracking.git

GazeTracking requires these dependencies:

  • NumPy
  • OpenCV 3.4
  • Dlib

To install them:

pip install -r requirements.txt

The Dlib library has four primary prerequisites: Boost, Boost.Python, CMake and X11/XQuartx. If you doesn't have them, you can read this article to know how to easily install them.

OpenCV 4 is not supported yet, make sure to install version 3.4

Run the demo:

python example.py

Simple Demo

import cv2
from gaze_tracking import GazeTracking


gaze = GazeTracking()

while True:
    gaze.refresh()

    frame = gaze.main_frame(True)
    text = ""

    if gaze.is_right():
        text = "Looking right"
    elif gaze.is_left():
        text = "Looking left"
    elif gaze.is_center():
        text = "Looking center"

    cv2.putText(frame, text, (60, 60), cv2.FONT_HERSHEY_DUPLEX, 2, (255, 0, 0), 2)
    cv2.imshow("Demo", frame)

    if cv2.waitKey(1) == 27:
        break

Documentation

In the following examples, gaze refers to an instance of the GazeTracking class.

Refresh the frame

gaze.refresh()

Captures a new frame with the webcam and analyzes it.

Position of the left pupil

gaze.pupil_left_coords()

Returns the coordinates (x,y) of the left pupil.

Position of the right pupil

gaze.pupil_right_coords()

Returns the coordinates (x,y) of the right pupil.

Looking to the left

gaze.is_left()

Returns True if the user is looking to the left.

Looking to the right

gaze.is_right()

Returns True if the user is looking to the right.

Looking at the center

gaze.is_center()

Returns True if the user is looking at the center.

Horizontal direction of the gaze

ratio = gaze.horizontal_ratio()

Returns a number between 0.0 and 1.0 that indicates the horizontal direction of the gaze. The extreme right is 0.0, the center is 0.5 and the extreme left is 1.0.

Vertical direction of the gaze

ratio = gaze.vertical_ratio()

Returns a number between 0.0 and 1.0 that indicates the vertical direction of the gaze. The extreme top is 0.0, the center is 0.5 and the extreme bottom is 1.0.

Blinking

gaze.is_blinking()

Returns True is the user's eyes are closed.

Webcam frame

# Without pupils highlighting
frame = gaze.main_frame(False)

# With pupils highlighting
frame = gaze.main_frame(True)

Returns the main frame from the webcam.

Licensing

This project is released by Antoine Lamé under the terms of the MIT Open Source License. View LICENSE for more information.

About

👀 Eye Tracking library easily implementable to your projects

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 95.1%
  • Shell 2.6%
  • Dockerfile 2.3%