diff --git a/camera_calibration/src/camera_calibration/mono_calibrator.py b/camera_calibration/src/camera_calibration/mono_calibrator.py index 326462a20..b35ee8ae5 100644 --- a/camera_calibration/src/camera_calibration/mono_calibrator.py +++ b/camera_calibration/src/camera_calibration/mono_calibrator.py @@ -115,8 +115,8 @@ def cal_fromcorners(self, good): raise NotImplemented( "Can't perform fisheye calibration with ChArUco board") - reproj_err, self.intrinsics, self.distortion, rvecs, tvecs = cv2.aruco.calibrateCameraCharuco( - ipts, ids, boards[0].charuco_board, self.size, intrinsics_in, None) + reproj_err, self.intrinsics, dist_coeffs, rvecs, tvecs = cv2.aruco.calibrateCameraCharuco( + ipts, ids, boards[0].charuco_board, self.size, intrinsics_in, None, flags=self.calib_flags) elif self.camera_model == CAMERA_MODEL.PINHOLE: print("mono pinhole calibration...") @@ -126,14 +126,7 @@ def cal_fromcorners(self, good): intrinsics_in, None, flags=self.calib_flags) - # OpenCV returns more than 8 coefficients (the additional ones all zeros) when CALIB_RATIONAL_MODEL is set. - # The extra ones include e.g. thin prism coefficients, which we are not interested in. - if self.calib_flags & cv2.CALIB_RATIONAL_MODEL: - # rational polynomial - self.distortion = dist_coeffs.flat[:8].reshape(-1, 1) - else: - # plumb bob - self.distortion = dist_coeffs.flat[:5].reshape(-1, 1) + elif self.camera_model == CAMERA_MODEL.FISHEYE: print("mono fisheye calibration...") # WARNING: cv2.fisheye.calibrate wants float64 points @@ -145,6 +138,14 @@ def cal_fromcorners(self, good): opts, ipts, self.size, intrinsics_in, None, flags=self.fisheye_calib_flags) + # OpenCV returns more than 8 coefficients (the additional ones all zeros) when CALIB_RATIONAL_MODEL is set. + # The extra ones include e.g. thin prism coefficients, which we are not interested in. + if self.pattern == Patterns.ChArUco or self.camera_model == CAMERA_MODEL.PINHOLE: + if self.calib_flags & cv2.CALIB_RATIONAL_MODEL: + self.distortion = dist_coeffs.flat[:8].reshape(-1, 1) # rational polynomial + else: + self.distortion = dist_coeffs.flat[:5].reshape(-1, 1) # plumb bob + # R is identity matrix for monocular calibration self.R = numpy.eye(3, dtype=numpy.float64) self.P = numpy.zeros((3, 4), dtype=numpy.float64)