[][src]Function opencv::calib3d::stereo_calibrate_camera_with_errors

pub fn stereo_calibrate_camera_with_errors(
    object_points: &dyn ToInputArray,
    image_points1: &dyn ToInputArray,
    image_points2: &dyn ToInputArray,
    camera_matrix1: &mut dyn ToInputOutputArray,
    dist_coeffs1: &mut dyn ToInputOutputArray,
    camera_matrix2: &mut dyn ToInputOutputArray,
    dist_coeffs2: &mut dyn ToInputOutputArray,
    image_size: Size,
    r: &mut dyn ToInputOutputArray,
    t: &mut dyn ToInputOutputArray,
    e: &mut dyn ToOutputArray,
    f: &mut dyn ToOutputArray,
    per_view_errors: &mut dyn ToOutputArray,
    flags: i32,
    criteria: &TermCriteria
) -> Result<f64>

Calibrates the stereo camera.

Parameters

  • objectPoints: Vector of vectors of the calibration pattern points.
  • imagePoints1: Vector of vectors of the projections of the calibration pattern points, observed by the first camera.
  • imagePoints2: Vector of vectors of the projections of the calibration pattern points, observed by the second camera.
  • cameraMatrix1: Input/output first camera matrix: inline formula , inline formula . If any of CALIB_USE_INTRINSIC_GUESS , CALIB_FIX_ASPECT_RATIO , CALIB_FIX_INTRINSIC , or CALIB_FIX_FOCAL_LENGTH are specified, some or all of the matrix components must be initialized. See the flags description for details.
  • distCoeffs1: Input/output vector of distortion coefficients inline formula of 4, 5, 8, 12 or 14 elements. The output vector length depends on the flags.
  • cameraMatrix2: Input/output second camera matrix. The parameter is similar to cameraMatrix1
  • distCoeffs2: Input/output lens distortion coefficients for the second camera. The parameter is similar to distCoeffs1 .
  • imageSize: Size of the image used only to initialize intrinsic camera matrix.
  • R: Output rotation matrix between the 1st and the 2nd camera coordinate systems.
  • T: Output translation vector between the coordinate systems of the cameras.
  • E: Output essential matrix.
  • F: Output fundamental matrix.
  • perViewErrors: Output vector of the RMS re-projection error estimated for each pattern view.
  • flags: Different flags that may be zero or a combination of the following values:
  • CALIB_FIX_INTRINSIC Fix cameraMatrix? and distCoeffs? so that only R, T, E , and F matrices are estimated.
  • CALIB_USE_INTRINSIC_GUESS Optimize some or all of the intrinsic parameters according to the specified flags. Initial values are provided by the user.
  • CALIB_USE_EXTRINSIC_GUESS R, T contain valid initial values that are optimized further. Otherwise R, T are initialized to the median value of the pattern views (each dimension separately).
  • CALIB_FIX_PRINCIPAL_POINT Fix the principal points during the optimization.
  • CALIB_FIX_FOCAL_LENGTH Fix inline formula and inline formula .
  • CALIB_FIX_ASPECT_RATIO Optimize inline formula . Fix the ratio inline formula .
  • CALIB_SAME_FOCAL_LENGTH Enforce inline formula and inline formula .
  • CALIB_ZERO_TANGENT_DIST Set tangential distortion coefficients for each camera to zeros and fix there.
  • CALIB_FIX_K1,...,CALIB_FIX_K6 Do not change the corresponding radial distortion coefficient during the optimization. If CALIB_USE_INTRINSIC_GUESS is set, the coefficient from the supplied distCoeffs matrix is used. Otherwise, it is set to 0.
  • CALIB_RATIONAL_MODEL Enable coefficients k4, k5, and k6. To provide the backward compatibility, this extra flag should be explicitly specified to make the calibration function use the rational model and return 8 coefficients. If the flag is not set, the function computes and returns only 5 distortion coefficients.
  • CALIB_THIN_PRISM_MODEL Coefficients s1, s2, s3 and s4 are enabled. To provide the backward compatibility, this extra flag should be explicitly specified to make the calibration function use the thin prism model and return 12 coefficients. If the flag is not set, the function computes and returns only 5 distortion coefficients.
  • CALIB_FIX_S1_S2_S3_S4 The thin prism distortion coefficients are not changed during the optimization. If CALIB_USE_INTRINSIC_GUESS is set, the coefficient from the supplied distCoeffs matrix is used. Otherwise, it is set to 0.
  • CALIB_TILTED_MODEL Coefficients tauX and tauY are enabled. To provide the backward compatibility, this extra flag should be explicitly specified to make the calibration function use the tilted sensor model and return 14 coefficients. If the flag is not set, the function computes and returns only 5 distortion coefficients.
  • CALIB_FIX_TAUX_TAUY The coefficients of the tilted sensor model are not changed during the optimization. If CALIB_USE_INTRINSIC_GUESS is set, the coefficient from the supplied distCoeffs matrix is used. Otherwise, it is set to 0.
  • criteria: Termination criteria for the iterative optimization algorithm.

The function estimates transformation between two cameras making a stereo pair. If you have a stereo camera where the relative position and orientation of two cameras is fixed, and if you computed poses of an object relative to the first camera and to the second camera, (R1, T1) and (R2, T2), respectively (this can be done with solvePnP ), then those poses definitely relate to each other. This means that, given ( inline formula,inline formula ), it should be possible to compute ( inline formula,inline formula ). You only need to know the position and orientation of the second camera relative to the first camera. This is what the described function does. It computes ( inline formula,inline formula ) so that:

block formula block formula

Optionally, it computes the essential matrix E:

block formula

where inline formula are components of the translation vector inline formula : inline formula . And the function can also compute the fundamental matrix F:

block formula

Besides the stereo-related information, the function can also perform a full calibration of each of two cameras. However, due to the high dimensionality of the parameter space and noise in the input data, the function can diverge from the correct solution. If the intrinsic parameters can be estimated with high accuracy for each of the cameras individually (for example, using calibrateCamera ), you are recommended to do so and then pass CALIB_FIX_INTRINSIC flag to the function along with the computed intrinsic parameters. Otherwise, if all the parameters are estimated at once, it makes sense to restrict some parameters, for example, pass CALIB_SAME_FOCAL_LENGTH and CALIB_ZERO_TANGENT_DIST flags, which is usually a reasonable assumption.

Similarly to calibrateCamera , the function minimizes the total re-projection error for all the points in all the available views from both cameras. The function returns the final value of the re-projection error.

C++ default parameters

  • flags: CALIB_FIX_INTRINSIC
  • criteria: TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 30, 1e-6)