title: OpenCV - How do I generate distortion coefficients and camera matrix for cv2.aruco.calibrateCameraCharucoExtended()
body: <p>How do I generate distortion coefficients and camera matrix for <code>cv2.aruco.calibrateCameraCharucoExtended()</code>?</p>
  <p>I am calibrating camera using <code>opencv-python 4.6</code> in built the <a href="https://docs.opencv.org/4.x/d9/d6a/group__aruco.html#ga54cf81c2e39119a84101258338aa7383" rel="nofollow noreferrer">cv2.aruco.calibrateCameraCharucoExtended()</a>.
  I try to initialize the <code>distortion coefficients</code> and the <code>camera matrix</code> for this function, but i am not realy sure how to do this.
  For the <code>distortion coefficients</code> i create a <code>numpy</code> array with Zeros.</p>
  <pre><code>distCoeffs=np.zeros((1,14))
  </code></pre>
  <pre><code>    (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 &amp; cv2.TERM_CRITERIA_COUNT, 10000, 1e-9))
  </code></pre>
  <p>The <code>camera matrix</code> usually contains:</p>
  <pre><code>cameraMatrix = np.array([[ f,  0.,  imageSize[0]/2 ],
                           [ 0.  f,   imageSize[1]/2 ],
                           [ 0.  0.   1])
  </code></pre>
  <p>The both parameters <code>cx</code> and <code>cy</code> can be found with this equation imageSize[0]/2 for <code>cx</code> and imageSize[1]/2 for <code>cy</code>.
  I don't know how to calculate the <code>focal length</code>.
  I fond something like this, for the <code>focal length</code>:</p>
  <pre><code>f = imsize[0] / (2 * np.tan(np.deg2rad(hfov/2)))
  </code></pre>
  <p><a href="https://www.edmundoptics.com/knowledge-center/application-notes/imaging/understanding-focal-length-and-field-of-view/" rel="nofollow noreferrer">Edmund Scientics</a> offered the following equation: f = (h.WD/Horizontal FOV)</p>
  <p>Is this the right way to create this both parameters the <code>distortion coefficients</code> and the <code>camera matrix</code>?</p>
  <p>Thanks!</p>