calibrel  0.2
More Accurate Pinhole Camera Calibration with Imperfect Planar Target
Functions
calrel Namespace Reference

Namespace calrel. More...

Functions

double calibrateCamera (InputArrayOfArrays imagePoints, Size imageSize, InputArray objectPoints, int fixedObjPt, InputOutputArray cameraMatrix, InputOutputArray distCoeffs, OutputArrayOfArrays rvecs, OutputArrayOfArrays tvecs, OutputArray newObjPoints, OutputArray stdDeviationsIntrinsics, OutputArray stdDeviationsExtrinsics, OutputArray stdDeviationsObjectPoints, OutputArray perViewErrors, int flags=0, TermCriteria criteria=TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 60, DBL_EPSILON *30))
 Finds the camera intrinsic and extrinsic parameters from several views of a calibration pattern. More...
 
double calibrateCamera (InputArrayOfArrays imagePoints, Size imageSize, InputArray objectPoints, int fixedObjPt, InputOutputArray cameraMatrix, InputOutputArray distCoeffs, OutputArrayOfArrays rvecs, OutputArrayOfArrays tvecs, OutputArray newObjPoints, int flags=0, TermCriteria criteria=TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 60, DBL_EPSILON *30))
 

Detailed Description

Namespace calrel.

Function Documentation

◆ calibrateCamera() [1/2]

double calrel::calibrateCamera ( InputArrayOfArrays  imagePoints,
Size  imageSize,
InputArray  objectPoints,
int  fixedObjPt,
InputOutputArray  cameraMatrix,
InputOutputArray  distCoeffs,
OutputArrayOfArrays  rvecs,
OutputArrayOfArrays  tvecs,
OutputArray  newObjPoints,
OutputArray  stdDeviationsIntrinsics,
OutputArray  stdDeviationsExtrinsics,
OutputArray  stdDeviationsObjectPoints,
OutputArray  perViewErrors,
int  flags = 0,
TermCriteria  criteria = TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 60, DBL_EPSILON *30) 
)

Finds the camera intrinsic and extrinsic parameters from several views of a calibration pattern.

Parameters
imagePointsIt is a vector of vectors of the projections of calibration pattern points (e.g. std::vector<std::vector<cv::Vec2f>>). imagePoints[i].size() must be equal to objectPoints.size() for each i.
imageSizeSize of the image used only to initialize the intrinsic camera matrix.
objectPointsIt is a vector of calibration pattern points in the calibration pattern coordinate space (e.g. std::vector<cv::Vec3f>). The same calibration pattern must be shown in each view and it is fully visible. The points are 3D, but since they are in a pattern coordinate system, then, if the rig is planar, it may make sense to put the model to a XY coordinate plane so that Z-coordinate of each input object point is 0. On output, the refined pattern points are returned for imperfect planar target.
fixedObjPtThe index of the 3D object point to be set as (d, 0, 0) as in Strobl's paper. Usually it is the top-right corner point of the calibration board grid.
cameraMatrixOutput 3x3 floating-point camera matrix \(\begin{bmatrix} f_x & 0 & c_x\\ 0 & f_y & c_y\\ 0 & 0 & 1 \end{bmatrix}\). If CV_CALIB_USE_INTRINSIC_GUESS and/or CALIB_FIX_ASPECT_RATIO are specified, some or all of fx, fy, cx, cy must be initialized before calling the function.
distCoeffsOutput vector of distortion coefficients \((k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6 [, s_1, s_2, s_3, s_4[, \tau_x, \tau_y]]]])\) of 4, 5, 8, 12 or 14 elements.
rvecsOutput vector of rotation vectors (see Rodrigues ) estimated for each pattern view (e.g. std::vector<cv::Mat>>). That is, each k-th rotation vector together with the corresponding k-th translation vector (see the next output parameter description) brings the calibration pattern from the model coordinate space (in which object points are specified) to the world coordinate space, that is, a real position of the calibration pattern in the k-th pattern view (k=0.. M -1).
tvecsOutput vector of translation vectors estimated for each pattern view.
newObjPointsThe updated output vector of pattern points.
stdDeviationsIntrinsicsOutput vector of standard deviations estimated for intrinsic parameters. Order of deviations values: \((f_x, f_y, c_x, c_y, k_1, k_2, p_1, p_2, k_3, k_4, k_5, k_6, s_1, s_2, s_3, s_4, \tau_x, \tau_y)\) If one of parameters is not estimated, it's deviation is equals to zero.
stdDeviationsExtrinsicsOutput vector of standard deviations estimated for extrinsic parameters. Order of deviations values: \((R_1, T_1, \dotsc , R_M, T_M)\) where M is number of pattern views, \(R_i, T_i\) are concatenated 1x3 vectors.
stdDeviationsObjectPointsOutput vector of standard deviations estimated for refined coordinates of calibration pattern points. It has the same size and order as objectPoints vector.
perViewErrorsOutput vector of the RMS re-projection error estimated for each pattern view.
flagsDifferent flags that may be zero or a combination of the following values:
  • CALIB_USE_INTRINSIC_GUESS cameraMatrix contains valid initial values of fx, fy, cx, cy that are optimized further. Otherwise, (cx, cy) is initially set to the image center ( imageSize is used), and focal distances are computed in a least-squares fashion. Note, that if intrinsic parameters are known, there is no need to use this function just to estimate extrinsic parameters. Use solvePnP instead.
  • CALIB_FIX_PRINCIPAL_POINT The principal point is not changed during the global optimization. It stays at the center or at a different location specified when CALIB_USE_INTRINSIC_GUESS is set too.
  • CALIB_FIX_ASPECT_RATIO The functions considers only fy as a free parameter. The ratio fx/fy stays the same as in the input cameraMatrix. When CALIB_USE_INTRINSIC_GUESS is not set, the actual input values of fx and fy are ignored, only their ratio is computed and used further.
  • CALIB_ZERO_TANGENT_DIST Tangential distortion coefficients \((p_1, p_2)\) are set to zeros and stay zero.
  • CALIB_FIX_K1,...,CALIB_FIX_K6 The corresponding radial distortion coefficient is 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_RATIONAL_MODEL Coefficients k4, k5, and k6 are enabled. 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.
criteriaTermination criteria for the iterative optimization algorithm.
Returns
the overall RMS re-projection error.

The function estimates the intrinsic camera parameters and extrinsic parameters for each of the views. The algorithm is based on Klaus H. Strobl and Gerd Hirzinger's paper "More Accurate Pinhole Camera Calibration with Imperfect Planar Target". The coordinates of 3D object points and their corresponding 2D projections in each view must be specified. That may be achieved by using an object with a known geometry and easily detectable feature points. Such an object is called a calibration rig or calibration pattern. Currently, initialization of intrinsic parameters (when CALIB_USE_INTRINSIC_GUESS is not set) is only implemented for planar calibration patterns (where Z-coordinates of the object points must be all zeros).

The algorithm performs the following steps:

  • Compute the initial intrinsic parameters (the option only available for planar calibration patterns) or read them from the input parameters. The distortion coefficients are all set to zeros initially unless some of CALIB_FIX_K? are specified.
  • Estimate the initial camera pose as if the intrinsic parameters have been already known. This is done using solvePnP.
  • Run the global Levenberg-Marquardt optimization algorithm to minimize the reprojection error, that is, the total sum of squared distances between the observed feature points imagePoints and the projected (using the current estimates for camera parameters and the poses) object points objectPoints. See projectPoints for details.

◆ calibrateCamera() [2/2]

double calrel::calibrateCamera ( InputArrayOfArrays  imagePoints,
Size  imageSize,
InputArray  objectPoints,
int  fixedObjPt,
InputOutputArray  cameraMatrix,
InputOutputArray  distCoeffs,
OutputArrayOfArrays  rvecs,
OutputArrayOfArrays  tvecs,
OutputArray  newObjPoints,
int  flags = 0,
TermCriteria  criteria = TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 60, DBL_EPSILON *30) 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.