From 6c8fc368195b8bec65500355294c19babaeb54a3 Mon Sep 17 00:00:00 2001 From: Jens Ahrensfeld Date: Thu, 11 Dec 2025 10:34:00 +0100 Subject: [PATCH] calibration: caller provides threshold --- ar_tag_pose/calibration.py | 8 +++++--- ar_tag_pose/detector_board_main.py | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/ar_tag_pose/calibration.py b/ar_tag_pose/calibration.py index 3effae6..dd5b354 100644 --- a/ar_tag_pose/calibration.py +++ b/ar_tag_pose/calibration.py @@ -42,13 +42,15 @@ class Calibration: calib = {'mtx': mtx.tolist(), 'dist': dist.tolist()} print(f"Saved {filename} successfully!") - def process(self, image: np.ndarray, r_vecs=None, t_vecs=None, flags=0): + def process(self, image: np.ndarray, thresh=3.0, r_vecs=None, t_vecs=None, flags=0): success = False - if len(self.obj_points_list) > 0 and len(self.img_points_list) > 0: + no = len(self.obj_points_list) + 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=r_vecs, tvecs=t_vecs, flags=flags) - if ret < 3: + if ret < thresh: success = True self.mtx = mtx self.dist = dist diff --git a/ar_tag_pose/detector_board_main.py b/ar_tag_pose/detector_board_main.py index 38b5bfc..87b6b51 100644 --- a/ar_tag_pose/detector_board_main.py +++ b/ar_tag_pose/detector_board_main.py @@ -185,7 +185,7 @@ class Detector(abc.ABC): print(f"{det}: Points matching success") elif k == ord('c'): gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY) - if self.calibration.process(gray): + if self.calibration.process(gray, thresh=3*len(self.detector)): print(f"{self.camera_name}: Camera calibration success") self.calibration.save(f"{RESULTS_FOLDER}/{self.camera_name}_cal.npz") elif k == ord('x'):