Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions camera_calibration/src/camera_calibration/mono_calibrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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...")
Expand All @@ -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
Expand All @@ -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)
Expand Down