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

Remove 3D pupil detector #2011

Merged
merged 16 commits into from
Dec 9, 2020
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions pupil_src/launchables/eye.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def load_runtime_pupil_detection_plugins():
continue
yield plugin

default_2d, default_3d, available_detectors = available_detector_plugins()
available_detectors = available_detector_plugins()
runtime_detectors = list(load_runtime_pupil_detection_plugins())
plugins = (
manager_classes
Expand Down Expand Up @@ -249,9 +249,7 @@ def load_runtime_pupil_detection_plugins():
# TODO: extend with plugins
(default_capture_name, default_capture_settings),
("UVC_Manager", {}),
# Detectors needs to be loaded first to set `g_pool.pupil_detector`
(default_2d.__name__, {}),
(default_3d.__name__, {}),
*[(p.__name__, {}) for p in available_detectors],
("NDSI_Manager", {}),
("HMD_Streaming_Manager", {}),
("File_Manager", {}),
Expand Down
16 changes: 5 additions & 11 deletions pupil_src/shared_modules/pupil_detector_plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,18 @@
import typing as T

from .detector_2d_plugin import Detector2DPlugin
from .detector_3d_plugin import Detector3DPlugin
from .detector_base_plugin import PupilDetectorPlugin, EVENT_KEY

logger = logging.getLogger(__name__)


def available_detector_plugins() -> T.Tuple[
PupilDetectorPlugin, PupilDetectorPlugin, T.List[PupilDetectorPlugin]
]:
"""Load and list available plugins, including default
def available_detector_plugins() -> T.List[T.Type[PupilDetectorPlugin]]:
"""Load and list available plugins

Returns tuple of default2D, default3D, and list of all detectors.
Returns list of all detectors.
"""

all_plugins = [Detector2DPlugin, Detector3DPlugin]
default2D = Detector2DPlugin
default3D = Detector3DPlugin
all_plugins: T.List[T.Type[PupilDetectorPlugin]] = [Detector2DPlugin]

try:
from .pye3d_plugin import Pye3DPlugin
Expand All @@ -39,6 +34,5 @@ def available_detector_plugins() -> T.Tuple[
else:
logger.info("Using refraction corrected 3D pupil detector.")
all_plugins.append(Pye3DPlugin)
default3D = Pye3DPlugin

return default2D, default3D, all_plugins
return all_plugins
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,38 @@
from methods import normalize
from plugin import Plugin

from .detector_base_plugin import PropertyProxy, PupilDetectorPlugin
from .detector_base_plugin import PupilDetectorPlugin
from .visualizer_2d import draw_pupil_outline

logger = logging.getLogger(__name__)


class Detector2DPlugin(PupilDetectorPlugin):
uniqueness = "by_class"
icon_font = "pupil_icons"
icon_chr = chr(0xEC18)

pupil_detection_identifier = "2d"
pupil_detection_method = "2d c++"

label = "C++ 2d detector"
identifier = "2d"
icon_font = "pupil_icons"
icon_chr = chr(0xEC18)
order = 0.100

@property
def pretty_class_name(self):
return "Pupil Detector 2D"

@property
def pupil_detector(self) -> DetectorBase:
return self.detector_2d

def __init__(
self, g_pool=None, namespaced_properties=None, detector_2d: Detector2D = None
self,
g_pool=None,
properties=None,
detector_2d: Detector2D = None,
):
super().__init__(g_pool=g_pool)
self.detector_2d = detector_2d or Detector2D(namespaced_properties or {})
self.proxy = PropertyProxy(self.detector_2d)
self.detector_2d = detector_2d or Detector2D(properties or {})

def detect(self, frame, **kwargs):
# convert roi-plugin to detector roi
Expand All @@ -60,28 +71,26 @@ def detect(self, frame, **kwargs):
color_img=debug_img,
roi=roi,
)
eye_id = self.g_pool.eye_id
location = result["location"]
result["norm_pos"] = normalize(
location, (frame.width, frame.height), flip_y=True

norm_pos = normalize(
result["location"], (frame.width, frame.height), flip_y=True
)
result["timestamp"] = frame.timestamp
result["topic"] = f"pupil.{eye_id}.{self.identifier}"
result["id"] = eye_id
result["method"] = "2d c++"
return result

@property
def pupil_detector(self) -> DetectorBase:
return self.detector_2d
# Create basic pupil datum
datum = self.create_pupil_datum(
norm_pos=norm_pos,
diameter=result["diameter"],
confidence=result["confidence"],
timestamp=frame.timestamp,
)

@property
def pretty_class_name(self):
return "Pupil Detector 2D"
# Fill out 2D model data
datum["ellipse"] = {}
datum["ellipse"]["axes"] = result["ellipse"]["axes"]
datum["ellipse"]["angle"] = result["ellipse"]["angle"]
datum["ellipse"]["center"] = result["ellipse"]["center"]

def gl_display(self):
if self._recent_detection_result:
draw_pupil_outline(self._recent_detection_result, color_rgb=(0, 0.5, 1))
return datum

def init_ui(self):
super().init_ui()
Expand All @@ -95,8 +104,8 @@ def init_ui(self):
self.menu.append(info)
self.menu.append(
ui.Slider(
"2d.intensity_range",
self.proxy,
"intensity_range",
self.pupil_detector_properties,
label="Pupil intensity range",
min=0,
max=60,
Expand All @@ -105,8 +114,8 @@ def init_ui(self):
)
self.menu.append(
ui.Slider(
"2d.pupil_size_min",
self.proxy,
"pupil_size_min",
self.pupil_detector_properties,
label="Pupil min",
min=1,
max=250,
Expand All @@ -115,11 +124,21 @@ def init_ui(self):
)
self.menu.append(
ui.Slider(
"2d.pupil_size_max",
self.proxy,
"pupil_size_max",
self.pupil_detector_properties,
label="Pupil max",
min=50,
max=400,
step=1,
)
)

def gl_display(self):
if self._recent_detection_result:
draw_pupil_outline(self._recent_detection_result, color_rgb=(0, 0.5, 1))

def on_resolution_change(self, old_size, new_size):
properties = {}
properties["pupil_size_max"] *= new_size[0] / old_size[0]
properties["pupil_size_min"] *= new_size[0] / old_size[0]
self.pupil_detector.update_properties(properties)
204 changes: 0 additions & 204 deletions pupil_src/shared_modules/pupil_detector_plugins/detector_3d_plugin.py

This file was deleted.

Loading