Skip to content

Instantly share code, notes, and snippets.

@papr
Created April 2, 2019 14:11
Show Gist options
  • Select an option

  • Save papr/eaecaf68e2e1bf09215f490d4b975517 to your computer and use it in GitHub Desktop.

Select an option

Save papr/eaecaf68e2e1bf09215f490d4b975517 to your computer and use it in GitHub Desktop.
Pupil Capture plugin gives feedback on the detection of circle markers
import cv2
from pyglui import ui
from pyglui.cygl.utils import draw_polyline, RGBA
from OpenGL.GL import GL_POLYGON
from circle_detector import CircleTracker
from plugin import Plugin
class Marker_Verification(Plugin):
def __init__(self, g_pool):
super().__init__(g_pool)
self.markers_visible = []
self.circle_tracker = CircleTracker()
def init_ui(self):
self.verification_button = ui.Thumb(
"markers_visible",
label=chr(0xEC14),
label_font="pupil_icons",
getter=lambda: len(self.markers_visible) > 0,
setter=lambda x: None,
)
self.g_pool.quickbar.append(self.verification_button)
def deinit_ui(self):
self.g_pool.quickbar.remove(self.verification_button)
self.verification_button = None
def recent_events(self, events):
frame = events.get("frame")
if frame:
gray_img = frame.gray
markers = self.circle_tracker.update(gray_img)
self.markers_visible = [
marker for marker in markers if marker["marker_type"] == "Ref"
]
self.verification_button.status_text = "{} marker(s) found".format(
len(self.markers_visible)
)
on_color = (
(0.0, 1.0, 0.0, 0.8)
if len(self.markers_visible) < 2
else (1.0, 0.0, 0.0, 0.8)
)
self.verification_button.on_color[:] = on_color
def gl_display(self):
for marker in self.markers_visible:
e = marker["ellipses"][-1]
pts = cv2.ellipse2Poly(
(int(e[0][0]), int(e[0][1])),
(int(e[1][0] / 2), int(e[1][1] / 2)),
int(e[-1]),
0,
360,
15,
)
draw_polyline(pts, 3.0, color=RGBA(0.0, 1.0, 0, 1.0))
if len(self.markers_visible) > 1:
draw_polyline(pts, 3.0, RGBA(1.0, 0.0, 0.0, 0.5), line_type=GL_POLYGON)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment