Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tom alphalab blink detection #634

Closed
wants to merge 13 commits into from
5 changes: 5 additions & 0 deletions src/.vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,11 @@ module.exports = {
"Build gaze-contingent assistive applications with Neon",
path: "gaze-contingency-assistive",
},
{
tpfffr marked this conversation as resolved.
Show resolved Hide resolved
title:
"Run Neon's blink detection pipeline offline or in real-time",
path: "blink-detection",
},
],
},
sidebarDepth: 1,
Expand Down
10 changes: 8 additions & 2 deletions src/alpha-lab/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ permalink: /alpha-lab/
# Welcome to Alpha Lab!

<div class="mb-4" style="display:flex;justify-content:center;">
<v-img class="rounded" :src="banner.img_name"
width="100%"
<v-img class="rounded" :src="banner.img_name"
width="100%"
:alt="banner.alt_text"
:title="banner.alt_text" />
</div>
Expand Down Expand Up @@ -130,6 +130,12 @@ export default {
to: "/alpha-lab/gaze-contingency-assistive",
img: "gaze-cont-main-page.png",
},
{
title: "Blink and you'll miss it!",
tpfffr marked this conversation as resolved.
Show resolved Hide resolved
text: "Run our blink detection pipeline offline and/or in real-time with Neon",
to: "/alpha-lab/blink-detection",
img: "eye_blink.gif",
},
],
banner: this.loadRandomImage(),
};
Expand Down
101 changes: 101 additions & 0 deletions src/alpha-lab/blink_detection.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
---
title: "Detecting eye blinks using Pupil Lab’s blink detection pipeline"
tpfffr marked this conversation as resolved.
Show resolved Hide resolved
description: Perform posthoc and real-time blink detection
permalink: /alpha-lab/blink-detection/
tags: [Neon, Realtime Python API]
---

# Detecting eye blinks using Pupil Lab's blink detection pipeline

<font size = 2>Products used: [Neon](https://pupil-labs.com/products/neon/), [Realtime Python API](https://pupil-labs-realtime-api.readthedocs.io/en/stable/)</font>

<div class="pb-4" style="display:flex;justify-content:left;">
<v-img
class="rounded"
:src="require('../media/alpha-lab/eye_blinks_anim.gif')"
max-width=800px
>
</v-img>
</div>

### Eye blinks: artifacts and information

The accurate detection of eye blinks serves a vital role in numerous eye tracking applications. Its importance is twofold: firstly, it helps identify time periods affected by blink-related artifacts, and secondly, isolate key physiological, cognitive, and clinical parameters, such as blink rate and blink duration. Blink detection can even be utilized in order to control external devices, for example by detecting a sequence of blinks made in quick succession. In order to show you how to achieve all of this, we have put together this guide.
tpfffr marked this conversation as resolved.
Show resolved Hide resolved

### Running blink detection locally

Eye blinks are automatically detected once your recording is uploaded to Pupil Cloud. This guide shows how to apply Pupil Labs' blink detection algorithm to Neon recordings <i>offline</i> (i.e., without using Pupil Cloud) or <i>in real-time</i> (using [Pupil Lab's Realtime Python API](https://github.com/pupil-labs/realtime-network-api)). This allows you to build novel applications or simply satisfy your curiosity and develop a deeper understanding of the underlying algorithms.
tpfffr marked this conversation as resolved.
Show resolved Hide resolved

::: tip
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**](https://docs.google.com/document/d/1JLBhC7fmBr6BR59IT3cWgYyqiaM8HLpFxv5KImrN-qE/export?format=pdf).
tpfffr marked this conversation as resolved.
Show resolved Hide resolved
:::

### Getting started

To get started, check out the accompanying [**GitHub repository**](https://github.com/pupil-labs/real-time-blink-detection). There you can find detailed instructions on how to install all required packages as well as a [**Jupyter notebook**](https://github.com/pupil-labs/real-time-blink-detection/blob/main/blink_detection.ipynb) 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.

### Results

#### Part 1: Posthoc blink detection

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

<div class="pb-4" style="display:flex;justify-content:left;">
<v-img
class="rounded"
:src="require('../media/alpha-lab/eye_blinks_statistics.png')"
max-width=500px
>
</v-img>
</div>

<font size=2>**Figure 1.** Blink statistics extracted from the provided example Neon recording.</font>

You will additionally get a visual representation of the detected blinks, providing an overview of their temporal distribution:


![Visual blink representation](../media/alpha-lab/eye_blinks_timeline.png)
<font size=2>**Figure 2.** Visual representation of the detected blinks in the example Neon recording. Green shaded areas depict detected blink events.</font>

When examining blink durations and the eyelid closing and re-opening times, you may notice that the total blink duration doesn't consistently 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. However, blink duration is calculated from the start time of the eyelid closing to the last frame identified as part of the re-opening sequence and will, thus, almost always be marginally longer than the sum of the individual events.<br>
tpfffr marked this conversation as resolved.
Show resolved Hide resolved

#### Part 2.1: Real-time blink detection

In the first section of Part 2 of the guide, you will learn how to estimate blink rate in quasi 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.
tpfffr marked this conversation as resolved.
Show resolved Hide resolved

<div class="pb-4" style="display:flex;justify-content:left;">
<v-img
class="rounded"
:src="require('../media/alpha-lab/eye_blinks_blinkrateest.png')"
max-width=450px
>
</v-img>
</div>

<font size=2>**Figure 3.** Realtime blink rate estimation. Shown is the blink rate estimated over the last 30 s (solid line) as well as the average blink rate for the entire recording (dashed line). </b></font>

#### Part 2.2: Toggling recordings remotely through eye blinks

In the last section of the guide, you will learn how to control a Neon device through a rapid sequence of three eye 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:

<div class="pb-4" style="display:flex;justify-content:left;">
<v-img
class="rounded"
:src="require('../media/alpha-lab/eye_blinks_toggle_recording.gif')"
max-width=350px
>
</v-img>
</div>

<!-- <div class="pb-4" style="display:flex;justify-content:left;">
<iframe width="400" height=258 src="https://www.youtube.com/embed/idAHOysl37Q?&mute=1&controls=0&autoplay=1&loop=1&playlist=idAHOysl37Q&rel=0">
</iframe>
</div> -->

### Conclusion
N-M-T marked this conversation as resolved.
Show resolved Hide resolved
In this Alpha Lab guide, we have shown you how you can use our blink detection pipeline, both offline as well as in real-time, and how you can build simple applications with it. We're excited to see what you will build using these tools.
N-M-T marked this conversation as resolved.
Show resolved Hide resolved
:::tip
If you need assistance in implementing or building your own application, reach out to us via email ([[email protected]](mailto:[email protected])), on our [Discord server](https://pupil-labs.com/chat/), or visit our [Support Page](https://pupil-labs.com/products/support/) for dedicated support options.
:::
Binary file added src/media/alpha-lab/eye_blink.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/media/alpha-lab/eye_blinks_anim.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/media/alpha-lab/eye_blinks_blinkrateest.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/media/alpha-lab/eye_blinks_statistics.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/media/alpha-lab/eye_blinks_timeline.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading