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 3 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
22 changes: 15 additions & 7 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,20 @@ def _setup_eye(self, eye_id, prefilled_config):
)
return overlay

def _video_path_for_eye(self, eye_id):
def _video_path_for_eye(self, eye_id: int) -> str:
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:

# Create eye video file filter for eye_id
file_filter = PupilRecording.FileFilter(rec_dir)
file_filter = file_filter.eye_id(eye_id)
file_filter = file_filter.videos()

# Get all eye videos for eye_id
eye_videos = list(file_filter)
papr marked this conversation as resolved.
Show resolved Hide resolved

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

def get_init_dict(self):
Expand Down
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 @@ -73,7 +77,9 @@ def render_pupil_2d(self, image, pupil_position):
def render_pupil_3d(self, image, pupil_position):
el = pupil_position["ellipse"]

conf = int(pupil_position["confidence"] * 255)
conf = pupil_position["confidence"] * 255
conf = float_to_int(conf)

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

if pupil_position["model_confidence"] <= 0.0:
Expand Down Expand Up @@ -112,7 +118,8 @@ def render_ellipse(self, image, ellipse, color):
outline = [np.asarray(outline, dtype="i")]
cv2.polylines(image, outline, True, color, thickness=1)

center = (int(ellipse["center"][0]), int(ellipse["center"][1]))
center = ellipse["center"]
center = (float_to_int(center[0]), float_to_int(center[1]))
romanroibu marked this conversation as resolved.
Show resolved Hide resolved
cv2.circle(image, center, 5, color, thickness=-1)

@staticmethod
Expand Down