From 767aeb325a8add7bbf857452cadaaa45e32a63a8 Mon Sep 17 00:00:00 2001 From: davidpagnon Date: Thu, 14 Nov 2024 17:35:59 +0100 Subject: [PATCH] remove CALIB_FIX_PRINCIPAL_POINT + convert objp to mm to avoid scale mismatch with intrinsics --- Pose2Sim/calibration.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Pose2Sim/calibration.py b/Pose2Sim/calibration.py index 385a5a3..e20057b 100644 --- a/Pose2Sim/calibration.py +++ b/Pose2Sim/calibration.py @@ -610,7 +610,7 @@ def calibrate_intrinsics(calib_dir, intrinsics_config_dict): img = cv2.imread(str(img_path)) objpoints = np.array(objpoints) ret_cam, mtx, dist, rvecs, tvecs = cv2.calibrateCamera(objpoints, imgpoints, img.shape[1::-1], - None, None, flags=(cv2.CALIB_FIX_K3 + cv2.CALIB_FIX_PRINCIPAL_POINT)) + None, None, flags=(cv2.CALIB_FIX_K3))# + cv2.CALIB_FIX_PRINCIPAL_POINT)) h, w = [np.float32(i) for i in img.shape[:-1]] ret.append(ret_cam) C.append(cam) @@ -709,8 +709,9 @@ def calibrate_extrinsics(calib_dir, extrinsics_config_dict, C, S, K, D): # Calculate extrinsics mtx, dist = np.array(K[i]), np.array(D[i]) - _, r, t = cv2.solvePnP(np.array(objp), imgp, mtx, dist) + _, r, t = cv2.solvePnP(np.array(objp)*1000, imgp, mtx, dist) r, t = r.flatten(), t.flatten() + t /= 1000 # Projection of object points to image plane # # Former way, distortions used to be ignored