Skip to content

Commit f7353e6

Browse files
authored
Merge pull request #1997 from pupil-labs/develop
Pupil v2.3 Release Candidate 1
2 parents fc89a04 + 985d5c2 commit f7353e6

File tree

10 files changed

+209
-222
lines changed

10 files changed

+209
-222
lines changed

pupil_src/shared_modules/camera_models.py

Lines changed: 160 additions & 202 deletions
Large diffs are not rendered by default.

pupil_src/shared_modules/pupil_recording/update/invisible.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
logger = logging.getLogger(__name__)
3030

31-
NEWEST_SUPPORTED_VERSION = Version("1.2")
31+
NEWEST_SUPPORTED_VERSION = Version("1.3")
3232

3333

3434
def transform_invisible_to_corresponding_new_style(rec_dir: str):
@@ -144,14 +144,15 @@ def _convert_gaze(recording: PupilRecording):
144144
"topic": "gaze.pi",
145145
"norm_pos": None,
146146
"timestamp": None,
147-
"confidence": 1.0,
147+
"confidence": None,
148148
}
149149
with fm.PLData_Writer(recording.rec_dir, "gaze") as writer:
150-
for ((x, y), ts) in pi_gaze_items(root_dir=recording.rec_dir):
150+
for ((x, y), ts, conf) in pi_gaze_items(root_dir=recording.rec_dir):
151151
template_datum["timestamp"] = ts
152152
template_datum["norm_pos"] = m.normalize(
153153
(x, y), size=(width, height), flip_y=True
154154
)
155+
template_datum["confidence"] = conf
155156
writer.append(template_datum)
156157
logger.info(f"Converted {len(writer.ts_queue)} gaze positions.")
157158

pupil_src/shared_modules/pupil_recording/update/old_style.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
import numpy as np
2222
from scipy.interpolate import interp1d
2323

24-
import camera_models as cm
2524
import csv_utils
2625
import file_methods as fm
26+
from camera_models import Camera_Model
2727
from version_utils import VersionFormat
2828

2929
from .. import Version
@@ -507,7 +507,7 @@ def make_update():
507507
f = world_video.streams.video[0].format
508508
resolution = f.width, f.height
509509

510-
intrinsics = cm.load_intrinsics(rec_dir, "world", resolution)
510+
intrinsics = Camera_Model.from_file(rec_dir, "world", resolution)
511511

512512
DEPRECATED_SQUARE_MARKER_KEY = "realtime_square_marker_surfaces"
513513
if DEPRECATED_SQUARE_MARKER_KEY not in surface_definitions_dict:

pupil_src/shared_modules/pupil_recording/update/update_utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def _try_patch_world_instrinsics_file(rec_dir: str, videos: T.Sequence[Path]) ->
3131
# Make sure the default value always correlates to the frame size of BrokenStream
3232
frame_size = (1280, 720)
3333
# TODO: Due to the naming conventions for multipart-recordings, we can't
34-
# easily lookup 'any' video name in the pre_recorded_calibrations, since it
34+
# easily lookup 'any' video name in the default_world_intrinsics, since it
3535
# might be a multipart recording. Therefore we need to compute a hint here
3636
# for the lookup. This could be improved.
3737
camera_hint = ""
@@ -41,7 +41,7 @@ def _try_patch_world_instrinsics_file(rec_dir: str, videos: T.Sequence[Path]) ->
4141
except av.AVError:
4242
continue
4343

44-
for camera in cm.pre_recorded_calibrations:
44+
for camera in cm.default_world_intrinsics:
4545
if camera in video.name:
4646
camera_hint = camera
4747
break
@@ -51,7 +51,7 @@ def _try_patch_world_instrinsics_file(rec_dir: str, videos: T.Sequence[Path]) ->
5151
)
5252
break
5353

54-
intrinsics = cm.load_intrinsics(rec_dir, camera_hint, frame_size)
54+
intrinsics = cm.Camera_Model.from_file(rec_dir, camera_hint, frame_size)
5555
intrinsics.save(rec_dir, "world")
5656

5757

pupil_src/shared_modules/recorder.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,9 @@ def start(self):
286286
frame = self.g_pool.capture._recent_frame
287287
if frame is None:
288288
logger.error(
289-
"Recording a Pupil Mobile stream requires a connection!"
290-
" Aborting recording."
289+
"Your connection does not seem to be stable enough for "
290+
"recording Pupil Mobile via WiFi. We recommend recording "
291+
"on the phone."
291292
)
292293
return
293294
if abs(frame.timestamp - start_time_synced) > TIMESTAMP_ERROR_THRESHOLD:

pupil_src/shared_modules/video_capture/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828

2929
import numpy as np
3030

31-
from camera_models import load_intrinsics
32-
3331
from .base_backend import (
3432
Base_Manager,
3533
Base_Source,

pupil_src/shared_modules/video_capture/file_backend.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import numpy as np
2323
from pyglui import ui
2424

25-
from camera_models import load_intrinsics
25+
from camera_models import Camera_Model
2626
from pupil_recording import PupilRecording
2727

2828
from .base_backend import Base_Manager, Base_Source, EndofVideoError, Playback_Source
@@ -245,7 +245,7 @@ def __init__(
245245
self.buffering = buffered_decoding
246246
# Load video split for first frame
247247
self.reset_video()
248-
self._intrinsics = load_intrinsics(rec, set_name, self.frame_size)
248+
self._intrinsics = Camera_Model.from_file(rec, set_name, self.frame_size)
249249

250250
self.show_plugin_menu = show_plugin_menu
251251

pupil_src/shared_modules/video_capture/ndsi_backend.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from pyglui import ui
1818

1919
import os_utils
20-
from camera_models import load_intrinsics
20+
from camera_models import Camera_Model
2121

2222
from .base_backend import Base_Manager, Base_Source, SourceInfo
2323

@@ -221,7 +221,7 @@ def on_notify(self, notification):
221221
@property
222222
def intrinsics(self):
223223
if self._intrinsics is None or self._intrinsics.resolution != self.frame_size:
224-
self._intrinsics = load_intrinsics(
224+
self._intrinsics = Camera_Model.from_file(
225225
self.g_pool.user_dir, self.name, self.frame_size
226226
)
227227
return self._intrinsics

pupil_src/shared_modules/video_capture/utils.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,16 @@ def find_raw_path(timestamps_path):
468468
assert raw_path.exists(), f"The file does not exist at path: {raw_path}"
469469
return raw_path
470470

471+
def find_worn_path(timestamps_path):
472+
worn_name = timestamps_path.name
473+
worn_name = worn_name.replace("gaze", "worn")
474+
worn_name = worn_name.replace("_timestamps", "")
475+
worn_path = timestamps_path.with_name(worn_name).with_suffix(".raw")
476+
if worn_path.exists():
477+
return worn_path
478+
else:
479+
return None
480+
471481
def load_timestamps_data(path):
472482
timestamps = np.load(str(path))
473483
return timestamps
@@ -478,6 +488,13 @@ def load_raw_data(path):
478488
raw_data.shape = (-1, 2)
479489
return np.asarray(raw_data, dtype=raw_data_dtype)
480490

491+
def load_worn_data(path):
492+
if not (path and path.exists()):
493+
return None
494+
495+
confidences = np.fromfile(str(path), "<u1") / 255.0
496+
return np.clip(confidences, 0.0, 1.0)
497+
481498
# This pattern will match any filename that:
482499
# - starts with "gaze ps"
483500
# - is followed by one or more digits
@@ -496,4 +513,16 @@ def load_raw_data(path):
496513
size = min(len(raw_data), len(timestamps))
497514
raw_data = raw_data[:size]
498515
timestamps = timestamps[:size]
499-
yield from zip(raw_data, timestamps)
516+
517+
conf_data = load_worn_data(find_worn_path(timestamps_path))
518+
if conf_data is not None and len(conf_data) != len(timestamps):
519+
logger.warning(
520+
f"There is a mismatch between the number of confidence data ({len(conf_data)}) "
521+
f"and the number of timestamps ({len(timestamps)})! Not using confidence data."
522+
)
523+
conf_data = None
524+
525+
if conf_data is None:
526+
conf_data = (1.0 for _ in range(len(timestamps)))
527+
528+
yield from zip(raw_data, timestamps, conf_data)

pupil_src/shared_modules/video_capture/uvc_backend.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
import gl_utils
2525
import uvc
26-
from camera_models import load_intrinsics
26+
from camera_models import Camera_Model
2727
from version_utils import VersionFormat
2828

2929
from .base_backend import Base_Manager, Base_Source, InitialisationError, SourceInfo
@@ -135,7 +135,7 @@ def __init__(
135135
self.frame_size_backup = frame_size
136136
self.frame_rate_backup = frame_rate
137137
self.exposure_time_backup = None
138-
self._intrinsics = load_intrinsics(
138+
self._intrinsics = Camera_Model.from_file(
139139
self.g_pool.user_dir, self.name, self.frame_size
140140
)
141141
else:
@@ -556,7 +556,7 @@ def frame_size(self, new_size):
556556
self.uvc_capture.frame_size = size
557557
self.frame_size_backup = size
558558

559-
self._intrinsics = load_intrinsics(
559+
self._intrinsics = Camera_Model.from_file(
560560
self.g_pool.user_dir, self.name, self.frame_size
561561
)
562562

0 commit comments

Comments
 (0)