Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix charuco rational polynomial distortion model calibration #2

Merged
merged 1 commit into from
Oct 1, 2024
Merged
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
19 changes: 11 additions & 8 deletions camera_calibration/src/camera_calibration/calibrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -776,8 +776,8 @@ def cal_fromcorners(self, good):
if self.camera_model == CAMERA_MODEL.FISHEYE:
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 @@ -787,12 +787,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:
self.distortion = dist_coeffs.flat[:8].reshape(-1, 1) # rational polynomial
else:
self.distortion = dist_coeffs.flat[:5].reshape(-1, 1) # plumb bob

elif self.camera_model == CAMERA_MODEL.FISHEYE:
print("mono fisheye calibration...")
# WARNING: cv2.fisheye.calibrate wants float64 points
Expand All @@ -804,6 +799,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