@@ -212,11 +212,15 @@ 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
+
215
219
# setup calibration flags & params based on cam_type and number of GCPs
216
220
if cam_type is not CameraType .fisheye :
217
221
calib_func = cv2 .calibrateCamera
218
222
# force square pixels always
219
- flags = cv2 .CALIB_FIX_ASPECT_RATIO
223
+ flags = cv2 .CALIB_FIX_ASPECT_RATIO | cv2 . CALIB_USE_INTRINSIC_GUESS
220
224
221
225
# fix initial intrinsic matrix if there are not enough GCPs to estimate all params (+3 is
222
226
# for 1 focal length and 2 principal points)
@@ -227,7 +231,7 @@ def fit_frame(
227
231
category = OrthorityWarning ,
228
232
stacklevel = 2 ,
229
233
)
230
- flags |= cv2 .CALIB_FIX_PRINCIPAL_POINT | cv2 .CALIB_FIX_FOCAL_LENGTH
234
+ flags |= cv2 .CALIB_FIX_PRINCIPAL_POINT | cv2 .CALIB_FIX_FOCAL_LENGTH
231
235
232
236
if cam_type is CameraType .pinhole :
233
237
# fix distortion at zero
@@ -247,7 +251,11 @@ def fit_frame(
247
251
calib_func = cv2 .fisheye .calibrate
248
252
# the oty fisheye camera does not have skew/alpha and CALIB_RECOMPUTE_EXTRINSIC improves
249
253
# accuracy
250
- flags = cv2 .fisheye .CALIB_FIX_SKEW | cv2 .fisheye .CALIB_RECOMPUTE_EXTRINSIC
254
+ flags = (
255
+ cv2 .fisheye .CALIB_FIX_SKEW
256
+ | cv2 .fisheye .CALIB_RECOMPUTE_EXTRINSIC
257
+ | cv2 .fisheye .CALIB_USE_INTRINSIC_GUESS
258
+ )
251
259
252
260
# Fix initial intrinsic matrix if there are not enough GCPs to estimate all params (+4 is
253
261
# for 2 focal lengths (you can't fix fisheye aspect ratio) and 2 principal points).
@@ -267,8 +275,6 @@ def fit_frame(
267
275
jis = [ji [None , :] for ji in jis ]
268
276
269
277
# calibrate
270
- K = np .eye (3 , dtype = 'float32' )
271
- dist_param = np .zeros (len (_frame_dist_params [cam_type ]), dtype = 'float32' )
272
278
err , K , dist_param , rs , ts = calib_func (
273
279
xyzs , jis , im_size , K , dist_param , flags = flags , criteria = criteria
274
280
)
0 commit comments