Skip to content

Instantly share code, notes, and snippets.

@Ramit110
Last active September 5, 2019 21:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ramit110/9d291f3d11565231ff720d24b7ead228 to your computer and use it in GitHub Desktop.
Save Ramit110/9d291f3d11565231ff720d24b7ead228 to your computer and use it in GitHub Desktop.
import csv
import logging
import os
from collections import deque
import numpy as np
import OpenGL.GL as gl
import pyglui.cygl.utils as cygl_utils
from pyglui import ui
from pyglui.pyfontstash import fontstash as fs
from scipy.signal import fftconvolve
import csv_utils
import data_changed
import file_methods as fm
import gl_utils
import player_methods as pm
from observable import Observable
from plugin import Analysis_Plugin_Base
logger = logging.getLogger(__name__)
activity_color = cygl_utils.RGBA(0.6602, 0.8594, 0.4609, 0.8)
blink_color = cygl_utils.RGBA(0.9961, 0.3789, 0.5313, 0.8)
threshold_color = cygl_utils.RGBA(0.9961, 0.8438, 0.3984, 0.8)
class Blink_Detect(Visualizer_Plugin_Base):
"""
Detects blinking
"""
order = 0.8
icon_chr = chr(0xE81A)
icon_font = "pupil_icons"
def __init__(
self, g_pool
):
super().__init__(g_pool)
self.order = 0.9
self.menu = None
self.history_length = history_length
self.history = deque()
def recent_events(self, events):
events["winks"] = []
self.history.extend(events.get("pupil", []))
try:
ts_oldest = self.history[0]["timestamp"]
ts_newest = self.history[-1]["timestamp"]
inconsistent_timestamps = ts_newest < ts_oldest
if inconsistent_timestamps:
self.history.clear()
return
age_threshold = ts_newest - self.history_length
# pop elements until only one element below the age threshold remains:
while self.history[1]["timestamp"] < age_threshold:
self.history.popleft() # remove outdated gaze points
except IndexError:
pass
filter_size = len(self.history)
if filter_size < 2 or ts_newest - ts_oldest < self.history_length:
return
activity = np.fromiter((pp["confidence"] for pp in self.history), dtype=float)
if((activity[0] <= 0.35) & (activity[1] >= 0.5)):
wink_type = "left"
elif((activity[1] <= 0.35) & (activity[0] >= 0.5)):
wink_type = "right"
else:
wink_type = "none"
logger.debug(
"{} wink detected with confidence {:0.3f}".format(wink_type, activity)
)
wink_entry = {
"topics": "winks",
"type": wink_type,
"confidence": activity,
"base_data": list(self.history),
"timestamp": self.history[len(self.history) // 2]["timestamp"],
}
events["winks"].append(wink_entry)
def init_ui(self):
# initialize the menu
self.add_menu()
def deinit_ui(self):
self.remove_menu()
def get_init_dict(self):
return {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment