From 352f3f880a1689592d9b0736d4e3d8673a6d1c9c Mon Sep 17 00:00:00 2001 From: Jens Ahrensfeld Date: Fri, 12 Dec 2025 13:35:29 +0100 Subject: [PATCH] - fixed: first undistort, then scale down --- ar_tag_pose/calibration.py | 3 ++- ar_tag_pose/detector_board_main.py | 11 +++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/ar_tag_pose/calibration.py b/ar_tag_pose/calibration.py index 0a9858d..604da14 100644 --- a/ar_tag_pose/calibration.py +++ b/ar_tag_pose/calibration.py @@ -59,6 +59,7 @@ class Calibration: return dst def process(self, image: np.ndarray, thresh=3.0): + flags = cv.CALIB_RATIONAL_MODEL + 0*cv.CALIB_FIX_PRINCIPAL_POINT criteria = (cv.TERM_CRITERIA_EPS + cv.TERM_CRITERIA_MAX_ITER, 3000, 0.001) success = False error = -1 @@ -66,7 +67,7 @@ class Calibration: ni = len(self.img_points_list) if no == ni and no > 0: ret, mtx, dist, r_vecs, t_vecs = cv.calibrateCamera(self.obj_points_list, self.img_points_list, image.shape, self.mtx, self.dist, - rvecs=None, tvecs=None, flags=cv.CALIB_RATIONAL_MODEL, criteria=criteria) + rvecs=None, tvecs=None, flags=flags, criteria=criteria) error = ret if ret < thresh: success = True diff --git a/ar_tag_pose/detector_board_main.py b/ar_tag_pose/detector_board_main.py index c37ffd7..f9a2aa9 100644 --- a/ar_tag_pose/detector_board_main.py +++ b/ar_tag_pose/detector_board_main.py @@ -239,9 +239,16 @@ class Detector(abc.ABC): self.print_angle(img,f"{str(det)}-{rotation_order}", rot, (30, int(y_pos/k_scale)), rotation_order, 1./k_scale) y_pos += 30 - img_scaled = cv.resize(img, dsize=None, fx=k_scale, fy=k_scale) + # show scaled version of input image if show_undistorted_image: - img_scaled = self.calibration.image_remap(img_scaled) + # undistort first + img_ud = self.calibration.image_remap(img) + # then scale + img_scaled = cv.resize(img_ud, dsize=None, fx=k_scale, fy=k_scale) + else: + # scale only + img_scaled = cv.resize(img, dsize=None, fx=k_scale, fy=k_scale) + cv.imshow('img', img_scaled) if self.out_file is not None: out = out_writer(out, img_scaled, filename=self.out_file)