Skip to content

Commit

Permalink
Fixes world intrinsics always using default values
Browse files Browse the repository at this point in the history
  • Loading branch information
domstoppable committed Feb 19, 2025
1 parent 6eb1546 commit 91551a6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 30 deletions.
3 changes: 0 additions & 3 deletions pupil_src/shared_modules/camera_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,9 +463,6 @@ def from_file(
:param cam_name: Name of the camera, e.g. 'Pupil Cam 1 ID2'.
:param resolution: Camera resolution.
"""
file_path = os.path.join(
directory, "{}.intrinsics".format(cam_name.replace(" ", "_"))
)
try:
return Camera_Model.all_from_file(directory, cam_name)[resolution]
except Exception:
Expand Down
40 changes: 13 additions & 27 deletions pupil_src/shared_modules/pupil_recording/update/update_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import typing as T
from pathlib import Path

import pupil_labs.neon_recording as nr

import av
import camera_models as cm
import numpy as np
Expand All @@ -26,33 +28,17 @@ def _try_patch_world_instrinsics_file(rec_dir: str, videos: T.Sequence[Path]) ->
if not videos:
return

# Make sure the default value always correlates to the frame size of BrokenStream
frame_size = (1280, 720)
# TODO: Due to the naming conventions for multipart-recordings, we can't
# easily lookup 'any' video name in the default_intrinsics, since it
# might be a multipart recording. Therefore we need to compute a hint here
# for the lookup. This could be improved.
camera_hint = ""
for video in videos:
try:
with av.open(str(video), format=video.suffix[1:]) as container:
if container.streams.video[0].format is None:
continue

for camera in cm.default_intrinsics:
if camera in video.name:
camera_hint = camera
break
frame_size = (
container.streams.video[0].format.width,
container.streams.video[0].format.height,
)
break
except av.AVError:
continue

intrinsics = cm.Camera_Model.from_file(rec_dir, camera_hint, frame_size)
intrinsics.save(rec_dir, "world")
recording = nr.load(Path(rec_dir).parent)

resolution = (recording.scene.width, recording.scene.height)
intrinsics = {
"camera_matrix": recording.calibration.scene_camera_matrix,
"dist_coefs": recording.calibration.scene_distortion_coefficients,
"cam_type": "radial"
}

camera = cm.Camera_Model._from_raw_intrinsics("world", resolution, intrinsics)
camera.save(rec_dir, "world")


_ConversionCallback = T.Callable[[np.array], np.array]
Expand Down

0 comments on commit 91551a6

Please sign in to comment.