Skip to content

Commit

Permalink
Added method to import CameraModel from ROS intrinsics calibration file
Browse files Browse the repository at this point in the history
  • Loading branch information
Tuxliri committed Jul 2, 2024
1 parent fb40c74 commit 2a89a14
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/dt_computer_vision/camera/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import cv2
import numpy as np
import yaml

from .utils import invert_map, ensure_ndarray

Expand Down Expand Up @@ -326,3 +327,17 @@ def from_native_objects(cls, data) -> 'CameraModel':
R=np.array(data['R']) if 'R' in data and data['R'] is not None else None,
H=np.array(data['H']) if data['H'] is not None else None
)

@classmethod
def from_ros_calibration(self, filestream):
"""
Import the camera calibration parameters from a ROS calibration file.
"""
data = yaml.safe_load(filestream)
K = np.array(data['camera_matrix']['data']).reshape(3, 3)
D = np.array(data['distortion_coefficients']['data'])
P = np.array(data['projection_matrix']['data']).reshape(3, 4)
R = np.array(data['rectification_matrix']['data']).reshape(3, 3)
width = data['image_width']
height = data['image_height']
return CameraModel(width, height, K, D, P, R)

0 comments on commit 2a89a14

Please sign in to comment.