Coder Social home page Coder Social logo

napoler / eyeloop Goto Github PK

View Code? Open in Web Editor NEW

This project forked from simonarvin/eyeloop

0.0 0.0 0.0 262.03 MB

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

License: GNU General Public License v3.0

Python 100.00%

eyeloop's Introduction

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 Importer work?
How does the Extractor work?

Getting started

Installation

Install EyeLoop simply by cloning the repository:

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

Dependencies: python -m pip install -r requirements.txt

Using pip: pip install .

You may want to use a Conda or Python virtual environment when installing eyeloop, to avoid mixing up with your system dependencies.

Using pip and a virtual environment:

python -m venv venv

source venv/bin/activate

(venv) pip install .

Alternatively:

  • numpy: python pip install numpy
  • opencv: python pip install opencv-python

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

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

Initiation

EyeLoop is initiated through the command-line utility eyeloop.

eyeloop

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

eyeloop --importer 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:

eyeloop --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.

eyeloop --model ellipsoid/circular

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

To see all command-line arguments, pass:

eyeloop --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:

eyeloop --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.

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.

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]


         

    

eyeloop's People

Contributors

simonarvin avatar cfculhane avatar kinow avatar sebalfa avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.