Skip to content

Instantly share code, notes, and snippets.

@mikelgg93
Created March 28, 2023 07:33
Show Gist options
  • Save mikelgg93/c8d6822cb20cc2a999ef1ab490121876 to your computer and use it in GitHub Desktop.
Save mikelgg93/c8d6822cb20cc2a999ef1ab490121876 to your computer and use it in GitHub Desktop.
Customise the recent gaze points vis in Pupil Capture

This Gist provides instructions on how to use a custom plugin that replaces the default Display Recent Gaze plugin in Pupil Capture.

Installation and Use

Like any other plugin, place it pupil_capture_settings > plugins and restart Pupil Capture, you should see a new plugin on the plugin menu named Custom Display Recent Gaze, this will allow you change the size, color and transparency of the circle drawn with the latest gaze points after calibration.

from gl_utils import draw_circle_filled_func_builder
from methods import denormalize
from plugin import Plugin
from plugin import Plugin as System_Plugin_Base
from pyglui.cygl.utils import RGBA
from pyglui import ui
class Display_Recent_Gaze(System_Plugin_Base):
"""
Custom_Display_Recent_Gaze shows the three most
recent gaze positions on the screen with adjustable color and size.
"""
def __init__(self, g_pool):
super().__init__(g_pool)
self.order = 0.8
self.uniqueness = "by_class"
self.icon_chr = chr(0xEC02)
self.icon_font = "pupil_icons"
self.pupil_display_list = []
self._draw_circle_filled = draw_circle_filled_func_builder()
self.menu = None
self.red = 1.0
self.green = 0.2
self.blue = 0.4
self.alpha = 0.8
self.size = 35
def init_ui(self):
self.add_menu()
self.menu.label = "Custom Display Recent Gaze"
self.menu.append(
ui.Info_Text(
"This is a custom plugin that replaces the default Display Recent Gaze plugin. It allows you to adjust the color and size of the gaze point shown after calibration."
)
)
self.menu.append(ui.Slider("red", self, label="Red", min=0, max=1, step=0.01))
self.menu.append(
ui.Slider("green", self, label="Green", min=0, max=1, step=0.01)
)
self.menu.append(ui.Slider("blue", self, label="Blue", min=0, max=1, step=0.01))
self.menu.append(
ui.Slider("alpha", self, label="Alpha", min=0, max=1, step=0.01)
)
self.menu.append(ui.Slider("size", self, label="Size", min=5, max=50, step=1))
def deinit_ui(self):
self.remove_menu()
def recent_events(self, events):
for pt in events.get("gaze", []):
recent_frame_size = self.g_pool.capture.frame_size
point = denormalize(pt["norm_pos"], recent_frame_size, flip_y=True)
self.pupil_display_list.append((point, pt["confidence"] * self.alpha))
self.pupil_display_list[:-3] = []
def gl_display(self):
for pt, a in self.pupil_display_list:
# This could be faster if there would be a method to also add multiple colors per point
self._draw_circle_filled(
tuple(pt),
size=self.size / 2,
color=RGBA(self.red, self.green, self.blue, a),
)
def get_init_dict(self):
return {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment