Skip to content

EyeLoop is a Python 3-based eye-tracker tailored specifically to dynamic, closed-loop experiments on consumer-grade hardware.

License

Notifications You must be signed in to change notification settings

sciencecorp/eyeloop

 
 

Repository files navigation

EyeLoop License: GPL v3 contributions welcome Build Status version lab beta

   

EyeLoop is a Python 3-based eye-tracker tailored specifically to dynamic, closed-loop experiments on consumer-grade hardware. This software is actively maintained: Users are encouraged to contribute to its development.

Features

  • High-speed > 1000 Hz on non-specialized hardware (no dedicated processing units necessary).
  • Modular, readable, customizable.
  • Open-source, and entirely Python 3.
  • Works on any platform, easy installation.
  • Actively maintained.

Overview

How it works

EyeLoop consists of two functional domains: the engine and the optional modules. The engine performs the eye-tracking, whereas the modules perform optional tasks, such as:

  • Experiments
  • Data acquisition
  • Importing video sequences to the engine

The modules import or extract data from the engine, and are therefore called Importers and Extractors, respectively.

One of EyeLoop's most appealing features is its modularity: Experiments are built simply by combining modules with the core Engine. Thus, the Engine has one task only: to compute eye-tracking data based on an imported sequence, and offer the generated data for extraction.

How does the Engine work?
How does the Source work?
How does the Extractor work?

Getting started

Installation

Requirements:

  • tkinter support (mac: brew install python-tk)

Install EyeLoop by cloning the repository:

git clone https://github.com/simonarvin/eyeloop.git

Install dependencies

You may want to use a virtual environment when installing eyeloop's dependencies, to avoid conflicts with your globally installed dependencies.

Using pip and a virtual environment:

python -m venv venv
source venv/bin/activate
(venv) pip install .

or, using pipenv

pipenv install

Install the module

pip install .

To download full examples with footage, check out EyeLoop's playground repository:

git clone https://github.com/simonarvin/eyeloop_playground.git

Initiation

Run with:

python eyeloop/run_eyeloop.py <...args>

E.g. running the eyeloop_playground human recording with its blink calibration:

python eyeloop/run_eyeloop.py -b=<...>/eyeloop_playground/examples/human/human-blinkcalibration.npy --video=<...>/eyeloop_playground/examples/human/human.mp4

To access the video sequence, EyeLoop must be connected to an appropriate importer class module. Usually, the default opencv source class (cv via cv_stream) is sufficient. For some machine vision cameras, however, a vimba-based source (vimba) may be neccessary.

python eyeloop/run_eyeloop.py --source cv/vimba

Click here for more information on importers.

To perform offline eye-tracking, we pass the video argument --video with the path of the video sequence:

python eyeloop/run_eyeloop.py --video [file]/[folder]

EyeLoop can be used on a multitude of eye types, including rodents, human and non-human primates. Specifically, users can suit their eye-tracking session to any species using the --model argument.

python eyeloop/run_eyeloop.py --model ellipsoid/circular

In general, the ellipsoid pupil model is best suited for rodents, whereas the circular model is best suited for primates.

To learn how to optimize EyeLoop for your video material, see EyeLoop Playground.

To see all command-line arguments, pass:

python eyeloop/run_eyeloop.py --help

Designing your first experiment

In EyeLoop, experiments are built by stacking modules. By default, EyeLoop imports two base extractors, namely a FPS-counter and a data acquisition tool. To add custom extractors, e.g., for experimental purposes, use the argument tag --extractors:

python eyeloop/run_eyeloop.py --extractors [file_path]/p (where p = file prompt)

Inside the extractor file, or a composite python file containing several extractors, define the list of extractors to be added:

extractors_add = [extractor1, extractor2, etc]

Extractors are instantiated by EyeLoop at start-up. Then, at every subsequent time-step, the extractor's fetch() function is called by the engine.

class Extractor:
    def __init__(self) -> None:
        ...
    def fetch(self, core) -> None:
        ...

fetch() gains access to all eye-tracking data in real-time via the core pointer. The fetch() method can return a value; the value will be stored in a dictionary of all extractor values for that time-step.

Click here for more information on extractors.

Open-loop example

As an example, we'll here design a simple open-loop experiment where the brightness of a PC monitor is linked to the phase of the sine wave function. We create anew python-file, say "test_ex.py", and in it define the sine wave frequency and phase using the instantiator:

class Experiment:
    def __init__(self) -> None:
        self.frequency = ...
        self.phase = 0

Then, by using fetch(), we shift the phase of the sine wave function at every time-step, and use this to control the brightness of a cv-render.

    ...
    def fetch(self, engine) -> None:
        self.phase += self.frequency
        sine = numpy.sin(self.phase) * .5 + .5
        brightness = numpy.ones((height, width), dtype=float) * sine
        cv2.imshow("Experiment", brightness)

To add our test extractor to EyeLoop, we'll need to define an extractors_add array:

extractors_add = [Experiment()]

Finally, we test the experiment by running command:

eyeloop --extractors path/to/test_ex.py

See Examples for demo recordings and experimental designs.

For extensive test data, see EyeLoop Playground

Data

EyeLoop produces a json-datalog for each eye-tracking session. The datalog's first column is the timestamp. The next columns define the pupil (if tracked):

((center_x, center_y), radius1, radius2, angle)

The next columns define the corneal reflection (if tracked):

((center_x, center_y), radius1, radius2, angle)

The next columns contain any data produced by custom Extractor modules

Graphical user interface

The default graphical user interface in EyeLoop is minimum-gui.

EyeLoop is compatible with custom graphical user interfaces through its modular logic. Click here for instructions on how to build your own.

Running unit tests

Install testing requirements by running in a terminal:

pip install -r requirements_testing.txt

Then run tox: tox

Reports and results will be outputted to /tests/reports

Known issues

  • Respawning/freezing windows when running minimum-gui in Ubuntu.

References

If you use any of this code or data, please cite [Arvin et al. 2020] (preprint).

@article {Arvin2020.07.03.186387,
	author = {Arvin, Simon and Rasmussen, Rune and Yonehara, Keisuke},
	title = {EyeLoop: An open-source, high-speed eye-tracker designed for dynamic experiments},
	elocation-id = {2020.07.03.186387},
	year = {2020},
	doi = {10.1101/2020.07.03.186387},
	publisher = {Cold Spring Harbor Laboratory},
	URL = {https://www.biorxiv.org/content/early/2020/07/04/2020.07.03.186387},
	eprint = {https://www.biorxiv.org/content/early/2020/07/04/2020.07.03.186387.full.pdf},
	journal = {bioRxiv}
}

License

This project is licensed under the GNU General Public License v3.0. Note that the software is provided "as is", without warranty of any kind, express or implied.

Authors

Lead Developer: Simon Arvin, [email protected]

Researchers:

Corresponding Author: Keisuke Yonehera, [email protected]


         

    

About

EyeLoop is a Python 3-based eye-tracker tailored specifically to dynamic, closed-loop experiments on consumer-grade hardware.

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%