1

How do I generate distortion coefficients and camera matrix for cv2.aruco.calibrateCameraCharucoExtended()?

I am calibrating camera using opencv-python 4.6 in built the cv2.aruco.calibrateCameraCharucoExtended(). I try to initialize the distortion coefficients and the camera matrix for this function, but i am not realy sure how to do this. For the distortion coefficients i create a numpy array with Zeros.

distCoeffs=np.zeros((1,14))
    (ret, camera_matrix, dist_coeffs,
     rotation_vectors, translation_vectors,
     std_deviationsion_intrinsics, std_deviations_extrinsics,
     per_view_errors) = cv2.aruco.calibrateCameraCharucoExtended(
                      charucoCorners=cornersList,            # charuco corners (box bounder)
                      charucoIds=idList,                     # charuco ids
                      board=board,                           #
                      imageSize=imageSize,                   # gray.shape
                      cameraMatrix=?,      #
                      distCoeffs=np.zeros((1,14)),           # initialized distortion coefficient 14 Elements
                      flags=flags,                           #
                      criteria=(cv2.TERM_CRITERIA_EPS & cv2.TERM_CRITERIA_COUNT, 10000, 1e-9))

The camera matrix usually contains:

cameraMatrix = np.array([[ f,  0.,  imageSize[0]/2 ],
                         [ 0.  f,   imageSize[1]/2 ],
                         [ 0.  0.   1])

The both parameters cx and cy can be found with this equation imageSize[0]/2 for cx and imageSize[1]/2 for cy. I don't know how to calculate the focal length. I fond something like this, for the focal length:

f = imsize[0] / (2 * np.tan(np.deg2rad(hfov/2)))

Edmund Scientics offered the following equation: f = (h.WD/Horizontal FOV)

Is this the right way to create this both parameters the distortion coefficients and the camera matrix?

Thanks!

I2I3
  • 31
  • 3
  • you have "a project" but you have many questions. perhaps formulate these questions explicitly. what are things you don't know, or are unsure about? you can [edit] your question. – Christoph Rackwitz Aug 06 '22 at 13:41
  • ok, just reading the title... you _don't_. leave those arguments blank (`None` if you must). the function is supposed to calculate those. it does not require you to know them. -- yes you can pre-populate those arrays with values. then the function will use those as initial values, but still optimize everything. your camera matrix is reasonably close (use `(w-1)/2` and `(h-1)/2` to be dead-on). focal length _can_ be calculated from field of view and image size. don't worry about a good estimate anyway. just put in `1000` and see how that fares. distortion coefficients: size 4 or 5, not 14. – Christoph Rackwitz Aug 07 '22 at 23:17
  • @ChristophRackwitz I tried a few days ago to leave the arguments blank None, did not work. After yout wrote me, it works, i saw the problem. The flag was wrong flags = (cv2.CALIB_USE_INTRINSIC_GUESS + cv2.CALIB_RATIONAL_MODEL + cv2.CALIB_FIX_ASPECT_RATIO). Thank you. – I2I3 Aug 08 '22 at 18:14

0 Answers0