@@ -212,13 +212,8 @@ def fit_frame(
212
212
"are {2}. The initial intrinsic matrix will not be globally optimised."
213
213
)
214
214
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
-
219
215
# setup calibration flags & params based on cam_type and number of GCPs
220
216
if cam_type is not CameraType .fisheye :
221
- calib_func = cv2 .calibrateCamera
222
217
# force square pixels always
223
218
flags = cv2 .CALIB_FIX_ASPECT_RATIO | cv2 .CALIB_USE_INTRINSIC_GUESS
224
219
@@ -242,20 +237,23 @@ def fit_frame(
242
237
# enable full OpenCV model
243
238
flags |= cv2 .CALIB_RATIONAL_MODEL | cv2 .CALIB_THIN_PRISM_MODEL | cv2 .CALIB_TILTED_MODEL
244
239
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
+ )
245
248
else :
246
249
# TODO: fisheye needs at least 5 gcps (per image or in ttl?) so the test above needs
247
250
# updating
248
251
# TODO: with >5 gcps fisheye.calibrate always runs, for low num gcps it seems to fix
249
252
# dist_param & K, but I'm not sure if this is based on the num gcps, or some numerical
250
253
# property of them
251
- calib_func = cv2 .fisheye .calibrate
252
254
# the oty fisheye camera does not have skew/alpha and CALIB_RECOMPUTE_EXTRINSIC improves
253
255
# 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
259
257
260
258
# Fix initial intrinsic matrix if there are not enough GCPs to estimate all params (+4 is
261
259
# for 2 focal lengths (you can't fix fisheye aspect ratio) and 2 principal points).
@@ -274,10 +272,10 @@ def fit_frame(
274
272
xyzs = [xyz [None , :] for xyz in xyzs ]
275
273
jis = [ji [None , :] for ji in jis ]
276
274
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
+ )
281
279
logger .debug (
282
280
f"RMS reprojection error for fit of '{ cam_type } ' model to { ttl_gcps } GCPs: { err :.4f} "
283
281
)
0 commit comments