Skip to content

Commit

Permalink
fix(intrinsic_camera_calibrator): cast arrays type while loading intr…
Browse files Browse the repository at this point in the history
…insic & correct function names (#217)

Signed-off-by: amadeuszsz <[email protected]>
  • Loading branch information
amadeuszsz authored Nov 28, 2024
1 parent 896c655 commit eef79a0
Showing 1 changed file with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def get_reprojection_errors(
return projected_points - image_points

def as_dict(self, alpha: float = 0.0) -> Dict:
undistorted = self._get_undistorted_camera_model_impl(alpha)
undistorted = self.get_undistorted_camera_model(alpha)
p = np.zeros((3, 4))
p[0:3, 0:3] = undistorted.k

Expand Down Expand Up @@ -191,18 +191,22 @@ def as_dict(self, alpha: float = 0.0) -> Dict:
def from_dict(self, d):
self.width = d["image_width"]
self.height = d["image_height"]
self.k = np.array(d["camera_matrix"]["data"]).reshape(
d["camera_matrix"]["rows"], d["camera_matrix"]["cols"]
self.k = (
np.array(d["camera_matrix"]["data"])
.reshape(d["camera_matrix"]["rows"], d["camera_matrix"]["cols"])
.astype(np.float64)
)
self.d = np.array(d["distortion_model"]["data"]).reshape(
d["distortion_model"]["rows"], d["distortion_model"]["cols"]
self.d = (
np.array(d["distortion_model"]["data"])
.reshape(d["distortion_model"]["rows"], d["distortion_model"]["cols"])
.astype(np.float64)
)

def update_config(self, **kwargs):
"""Update the camera model configuration."""
self._update_config_impl(**kwargs)

def _get_undistorted_camera_model_impl(self, alpha: float):
def get_undistorted_camera_model(self, alpha: float):
"""Compute the undistorted version of the camera model."""
undistorted_k, _ = cv2.getOptimalNewCameraMatrix(
self.k, self.d, (self.width, self.height), alpha
Expand All @@ -212,9 +216,9 @@ def _get_undistorted_camera_model_impl(self, alpha: float):
k=undistorted_k, d=np.zeros_like(self.d), height=self.height, width=self.width
)

def _rectify_impl(self, img: np.array, alpha=0.0) -> np.array:
def rectify(self, img: np.array, alpha=0.0) -> np.array:
"""Rectifies an image using the current camera model. Alpha is a value in the [0,1] range to regulate how the rectified image is cropped. 0 means that all the pixels in the rectified image are valid whereas 1 keeps all the original pixels from the unrectified image into the rectifies one, filling with zeroes the invalid pixels."""
if np.abs(self.d).sum() == 0:
if np.all(self.d == 0.0):
return img

if self._cached_undistorted_model is None or alpha != self._cached_undistortion_alpha:
Expand Down

0 comments on commit eef79a0

Please sign in to comment.