The accurate detection of blinks serves a vital role in many eye tracking applications. Its importance is twofold: firstly, it helps identify time periods affected by blink-related artifacts, and secondly, blink statistics can serve as relevant physiological, cognitive, and clinical parameters. Blink detection can even be utilized in order to control external devices, for example by detecting a sequence of blinks made in quick succession.
Blinks are automatically detected once your recording is uploaded to Pupil Cloud or processed with Neon Player desktop software. This guide shows how to apply Pupil Labs' blink detection algorithm to Neon recordings programmatically, offline or in real-time using Pupil Lab's Realtime Python API. This allows you to build novel applications or simply satisfy your curiosity and develop a deeper understanding of the underlying algorithms.
If you are interested in learning more about the technical details of the underlying blink detection pipeline, we invite you to also have a look at our white paper.
To get started, check out the accompanying GitHub repository. There you can find detailed instructions on how to install all required packages as well as a Jupyter notebook that contains all the code needed along with instructions on how to run everything.
If you don't have a recording at hand, worry not! The GitHub repository comes with an example Neon recording that you can explore.
Once you have run the first part of the notebook, you will get an output from which you can derive a number of statistics that provide various insights about your recording: the total number of detected blinks, the estimated blink rate (in Hz), and the average blink duration (in seconds), as well as eyelid closing and re-opening durations (in seconds).
You will additionally get a visual representation of the detected blinks, providing an overview of their temporal distribution:
The blink detector is designed to classify samples into eye lid opening and closing phases.
Note that, due to the design of the blink detector, the total blink duration doesn't (necessarily) equate to the sum of the durations of the closing and re-opening phases. This discrepancy arises because there are some frames during the period between closing and reopening of the eyelids where there is negligible movement, and thus, they are not classified as part of either the opening or the closing phase. As the total blink duration is calculated from the start time of the eyelid closing to the last frame identified as part of the re-opening sequence, it will, thus, almost always be marginally longer than the sum of the individual events.
In the first section of Part 2 of the notebook, you will learn how to estimate blink rate in real-time. From this, you will obtain a graph, as shown below, that is updated with every blink and shows an estimate of the current blink rate.
2.2. Toggling Recordings Remotely Through Blinks
In the last section of the notebook, you will learn how to control a Neon device through a rapid sequence of three blinks. Upon detection of said sequence, the companion device will initiate a new recording or stop an ongoing one, as illustrated in the video below: