Start » Filter Reference » OpenCV » Camera Calibration And 3D Reconstruction » cvCalibrateCamera

cvCalibrateCamera


Module: OpenCV

Finds the camera intrinsic and extrinsic parameters from pairs of corresponding image and object points arrays.

Name Type Range Description
Input value
inObjectPoints Point3DArrayArray
Input value
inImagePoints Point2DArrayArray
Input value
inImageWidth Integer 1 - Width of image, used for initializing principal point.
Input value
inImageHeight Integer 1 - Height of image, used for initializing principal point.
Input value
inFixPrincipalPoint Bool The principal point is not changed during the global optimization. It stays in the center of the image, or as in the initial camera matrix.
Input value
inFixAspectRatio Bool The functions considers only fy as a free parameter. The ratio fx/fy stays 1, or as in the initial camera matrix.
Input value
inZeroTangentDist Bool Tangential distortion coefficients (p_1, p_2) are assumed zero.
Input value
inRationalModel Bool Additional distortion coefficients (k_4, k_5, k_6) are calculated.
Input value
inInitialCameraMatrix Matrix* Optional initial camera matrix, required for inFixPrincipalPoint and inFixAspectRatio.
Output value
outCameraMatrix Matrix Matrix of intrinsic parameters
Output value
outDistCoeffs Matrix Coefficients of distortion
Output value
outRVecs Vector3DArray Array with values of rotations for each points set
Output value
outTVecs Vector3DArray Array with values of translations for each points set
Output value
outError Real Final re-projection error value

Description

The function estimates the intrinsic camera parameters and extrinsic parameters for each of the views. The algorithm is based on [Zhang2000] and [BoughuetMCT]. 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, and AvOpenCV has built-in support for a chessboard as a calibration rig (see cvFindChessboardCorners). Currently, initialization of intrinsic parameters (when CV_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). 3D calibration rigs can also be used as long as initial cameraMatrix is provided.

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.
  • Estimate the initial camera pose as if the intrinsic parameters have been already known.
  • 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.

When camera matrix and distortion coefficients are calculated, one can create undistortion maps using cvInitUndistortRectifyMap function. These maps can be applied to images using cvRemap. Also raw camera matrix and distortion coefficients matrices can be applied to image using cvUndistort filter.

Errors

This filter can throw an exception to report error. Read how to deal with errors in Error Handling.

List of possible exceptions:

Error type Description
DomainError in are required to perform camera calibration in cvCalibrateCamera.
DomainError in are required to perform camera calibration in cvCalibrateCamera.
DomainError Fixing aspect ratio requested, but no initial camera matrix passed in cvCalibrateCamera.
DomainError Fixing principal point requested, but no initial camera matrix passed in cvCalibrateCamera.
DomainError Inconsistent sizes of inImagePoints and inObjectPoints in cvCalibrateCamera.
DomainError inInitialCameraMatrix must be a 3x3 matrix in cvCalibrateCamera.
DomainError Missing inImagePoints or inObjectPoints in cvCalibrateCamera.

Complexity Level

This filter is available on Basic Complexity Level.

See Also

  • cvRemap – Applies a generic geometrical transformation to the image.
  • cvUndistort – Transforms an image to compensate for lens distortion.