Skip to content

Commit 29ffdc9

Browse files
committed
allow fisheye.calibrate() to initialise instrinsic
1 parent 39895b6 commit 29ffdc9

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

orthority/fit.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -212,13 +212,8 @@ def fit_frame(
212212
"are {2}. The initial intrinsic matrix will not be globally optimised."
213213
)
214214

215-
# initial interior params
216-
K = cv2.initCameraMatrix2D(xyzs, jis, im_size)
217-
dist_param = np.zeros(len(_frame_dist_params[cam_type]), dtype='float32')
218-
219215
# setup calibration flags & params based on cam_type and number of GCPs
220216
if cam_type is not CameraType.fisheye:
221-
calib_func = cv2.calibrateCamera
222217
# force square pixels always
223218
flags = cv2.CALIB_FIX_ASPECT_RATIO | cv2.CALIB_USE_INTRINSIC_GUESS
224219

@@ -242,20 +237,23 @@ def fit_frame(
242237
# enable full OpenCV model
243238
flags |= cv2.CALIB_RATIONAL_MODEL | cv2.CALIB_THIN_PRISM_MODEL | cv2.CALIB_TILTED_MODEL
244239

240+
# initial interior params
241+
K = cv2.initCameraMatrix2D(xyzs, jis, im_size)
242+
dist_param = np.zeros(len(_frame_dist_params[cam_type]), dtype='float32')
243+
244+
# calibrate
245+
err, K, dist_param, rs, ts = cv2.calibrateCamera(
246+
xyzs, jis, im_size, K, dist_param, flags=flags, criteria=criteria
247+
)
245248
else:
246249
# TODO: fisheye needs at least 5 gcps (per image or in ttl?) so the test above needs
247250
# updating
248251
# TODO: with >5 gcps fisheye.calibrate always runs, for low num gcps it seems to fix
249252
# dist_param & K, but I'm not sure if this is based on the num gcps, or some numerical
250253
# property of them
251-
calib_func = cv2.fisheye.calibrate
252254
# the oty fisheye camera does not have skew/alpha and CALIB_RECOMPUTE_EXTRINSIC improves
253255
# accuracy
254-
flags = (
255-
cv2.fisheye.CALIB_FIX_SKEW
256-
| cv2.fisheye.CALIB_RECOMPUTE_EXTRINSIC
257-
| cv2.fisheye.CALIB_USE_INTRINSIC_GUESS
258-
)
256+
flags = cv2.fisheye.CALIB_FIX_SKEW | cv2.fisheye.CALIB_RECOMPUTE_EXTRINSIC
259257

260258
# Fix initial intrinsic matrix if there are not enough GCPs to estimate all params (+4 is
261259
# for 2 focal lengths (you can't fix fisheye aspect ratio) and 2 principal points).
@@ -274,10 +272,10 @@ def fit_frame(
274272
xyzs = [xyz[None, :] for xyz in xyzs]
275273
jis = [ji[None, :] for ji in jis]
276274

277-
# calibrate
278-
err, K, dist_param, rs, ts = calib_func(
279-
xyzs, jis, im_size, K, dist_param, flags=flags, criteria=criteria
280-
)
275+
# calibrate
276+
err, K, dist_param, rs, ts = cv2.fisheye.calibrate(
277+
xyzs, jis, im_size, None, None, flags=flags, criteria=criteria
278+
)
281279
logger.debug(
282280
f"RMS reprojection error for fit of '{cam_type}' model to {ttl_gcps} GCPs: {err:.4f}"
283281
)

0 commit comments

Comments
 (0)