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

Fix eye overlay plugin visualizing invalid data #2021

Merged
merged 5 commits into from Oct 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions pupil_src/shared_modules/pupil_recording/recording.py
Expand Up @@ -113,6 +113,9 @@ def eyes(self) -> FilterType:
"eye0", "eye1", mode=PupilRecording.FileFilter.FilterMode.UNION
)

def eye_id(self, eye_id: int) -> FilterType:
return self.filter(f"eye{eye_id}")

def videos(self) -> FilterType:
return self.filter("videos")

Expand Down
18 changes: 10 additions & 8 deletions pupil_src/shared_modules/video_overlay/plugins/eye_overlay.py
Expand Up @@ -21,6 +21,8 @@
from video_overlay.ui.management import UIManagementEyes
from video_overlay.utils.constraints import ConstraintedValue, BooleanConstraint

from pupil_recording import PupilRecording


class Eye_Overlay(Observable, Plugin):
icon_chr = chr(0xEC02)
Expand Down Expand Up @@ -94,14 +96,14 @@ def _setup_eye(self, eye_id, prefilled_config):
)
return overlay

def _video_path_for_eye(self, eye_id):
rec_dir = self.g_pool.rec_dir
video_file_pattern = "eye{}.*".format(eye_id)
video_path_pattern = os.path.join(rec_dir, video_file_pattern)
try:
video_path_candidates = glob.iglob(video_path_pattern)
return next(video_path_candidates)
except StopIteration:
def _video_path_for_eye(self, eye_id: int) -> str:
# Get all eye videos for eye_id
recording = PupilRecording(self.g_pool.rec_dir)
eye_videos = list(recording.files().videos().eye_id(eye_id))

if eye_videos:
return str(eye_videos[0])
else:
return "/not/found/eye{}.mp4".format(eye_id)

def get_init_dict(self):
Expand Down
25 changes: 21 additions & 4 deletions pupil_src/shared_modules/video_overlay/utils/image_manipulation.py
Expand Up @@ -18,6 +18,10 @@
logger = logging.getLogger(__name__)


def float_to_int(value: float) -> int:
return int(value) if np.isfinite(value) else 0


class ImageManipulator(metaclass=abc.ABCMeta):
@abc.abstractmethod
def apply_to(self, image, parameter, **kwargs):
Expand Down Expand Up @@ -67,14 +71,20 @@ def apply_to(self, image, parameter, *, is_fake_frame, **kwargs):
def render_pupil_2d(self, image, pupil_position):
el = pupil_position["ellipse"]

conf = int(pupil_position["confidence"] * 255)
self.render_ellipse(image, el, color=(255, 127, 0, conf))
conf = pupil_position["confidence"] * 255
conf = float_to_int(conf)

if conf > 0:
self.render_ellipse(image, el, color=(255, 127, 0, conf))

def render_pupil_3d(self, image, pupil_position):
el = pupil_position["ellipse"]

conf = int(pupil_position["confidence"] * 255)
self.render_ellipse(image, el, color=(0, 0, 255, conf))
conf = pupil_position["confidence"] * 255
conf = float_to_int(conf)

if conf > 0:
self.render_ellipse(image, el, color=(0, 0, 255, conf))

if pupil_position["model_confidence"] <= 0.0:
# NOTE: if 'model_confidence' == 0, some values of the 'projected_sphere'
Expand Down Expand Up @@ -106,6 +116,13 @@ def render_pupil_3d(self, image, pupil_position):
)

def render_ellipse(self, image, ellipse, color):
if not all(np.isfinite(ellipse["center"])):
return
if not all(np.isfinite(ellipse["axes"])):
return
if not np.isfinite(ellipse["angle"]):
return

outline = self.get_ellipse_points(
ellipse["center"], ellipse["axes"], ellipse["angle"]
)
Expand Down