OpenCV Camera Calibration Functions
Rotation and Transformation Functions
Rodrigues
Converts a rotation matrix to a rotation vector or vice versa.
This function performs conversion between different representations of rotations in 3D space. The rotation vector (also called axis-angle representation) is a compact way to represent rotations using only 3 parameters.
Parameters: - src
: Input rotation vector (3x1 or 1x3) or rotation matrix (3x3) - dst
: Output rotation matrix (3x3) or rotation vector (3x1 or 1x3) - jacobian
: Optional output Jacobian matrix (9x3 or 3x9) for optimization algorithms
Conversion Process: - Vector to Matrix: Uses Rodrigues’ rotation formula - Matrix to Vector: Extracts axis-angle representation from rotation matrix
findHomography
Finds a perspective transformation between two planes.
This function finds the homography matrix that maps points from one plane to another. It’s essential for image rectification, panorama stitching, and planar object tracking.
Parameters: - srcPoints
: Coordinates of points in the original plane - dstPoints
: Coordinates of points in the target plane
- method
: Method used to compute homography: - 0
: Regular method using all points - RANSAC
: RANSAC-based robust method - LMEDS
: Least-Median robust method - RHO
: PROSAC-based robust method - ransacReprojThreshold
: Maximum allowed reprojection error for RANSAC - mask
: Optional output mask of inliers - maxIters
: Maximum number of RANSAC iterations - confidence
: Confidence level for RANSAC
Returns: 3x3 homography matrix or empty matrix if computation fails
RQDecomp3x3
Computes an RQ decomposition of 3x3 matrices.
This function decomposes a 3x3 matrix into the product of an upper triangular matrix R and an orthogonal matrix Q. This is particularly useful in camera calibration for decomposing projection matrices.
Parameters: - src
: 3x3 input matrix - mtxR
: Output 3x3 upper-triangular matrix R - mtxQ
: Output 3x3 orthogonal matrix Q - Qx
, Qy
, Qz
: Optional 3x3 rotation matrices around x, y, z axes
decomposeProjectionMatrix
Decomposes a projection matrix into a rotation matrix and a camera intrinsic matrix.
This function is useful for extracting camera parameters from a known projection matrix, which is the product of the intrinsic and extrinsic camera matrices.
Parameters: - projMatrix
: 3x4 input projection matrix - cameraMatrix
: Output 3x3 camera intrinsic matrix - rotMatrix
: Output 3x3 rotation matrix - transVect
: Output 4x1 translation vector - rotMatrixX
, rotMatrixY
, rotMatrixZ
: Optional rotation matrices around coordinate axes - eulerAngles
: Optional 3x1 Euler angles
matMulDeriv
Computes partial derivatives of the matrix product for each multiplied matrix.
This function is useful in optimization algorithms where gradients of matrix products are needed.
composeRT
Combines two rotation-and-shift transformations.
This function combines two transformations represented by rotation matrices/vectors and translation vectors into a single transformation.
Parameters: - rvec1
, tvec1
: First transformation (rotation vector and translation) - rvec2
, tvec2
: Second transformation
- rvec3
, tvec3
: Output combined transformation - dr3dr1
, dr3dt1
, dr3dr2
, dr3dt2
, dt3dr1
, dt3dt1
, dt3dr2
, dt3dt2
: Optional Jacobian matrices
3D Point Projection and Pose Estimation
projectPoints
Projects 3D points to an image plane.
This function projects 3D object points to 2D image points using the camera’s intrinsic and extrinsic parameters. It’s fundamental for rendering, augmented reality, and pose verification.
Parameters: - objectPoints
: Array of 3D object points - rvec
: Rotation vector (3x1/1x3) or rotation matrix (3x3) - tvec
: Translation vector (3x1/1x3) - cameraMatrix
: Camera intrinsic matrix (3x3) - distCoeffs
: Input distortion coefficients - imagePoints
: Output array of 2D image point projections - jacobian
: Optional output Jacobian matrix for optimization - aspectRatio
: Optional aspect ratio parameter
solvePnP
Finds an object pose from 3D-2D point correspondences.
This function estimates the object’s pose (rotation and translation) that transforms 3D object points to their corresponding 2D image projections.
Parameters: - objectPoints
: Array of 3D object points in object coordinate space - imagePoints
: Array of corresponding 2D image points - cameraMatrix
: Input camera intrinsic matrix - distCoeffs
: Input distortion coefficients - rvec
: Output rotation vector - tvec
: Output translation vector
- useExtrinsicGuess
: Use provided rvec and tvec as initial estimates - flags
: Method for solving PnP problem: - SOLVEPNP_ITERATIVE
: Iterative method based on Levenberg-Marquardt - SOLVEPNP_EPNP
: EPnP method - SOLVEPNP_P3P
: P3P method (requires exactly 4 points) - SOLVEPNP_DLS
: DLS method - SOLVEPNP_UPNP
: UPnP method - SOLVEPNP_AP3P
: AP3P method - SOLVEPNP_IPPE
: IPPE method - SOLVEPNP_IPPE_SQUARE
: IPPE method for square targets
solvePnPRansac
Finds an object pose from 3D-2D point correspondences using RANSAC scheme to deal with bad matches.
This is the robust version of solvePnP that can handle outliers in the point correspondences.
Parameters: - objectPoints
: Array of 3D object points - imagePoints
: Array of corresponding 2D image points - cameraMatrix
: Input camera intrinsic matrix - distCoeffs
: Input distortion coefficients - rvec
: Output rotation vector - tvec
: Output translation vector - useExtrinsicGuess
: Use provided estimates as initial guess - iterationsCount
: Number of iterations (default: 100) - reprojectionError
: Inlier threshold value (default: 8.0) - confidence
: Algorithm confidence (default: 0.99) - inliers
: Output vector of inlier indices - flags
: Method for solving PnP problem
solveP3P
Finds an object pose from 3 3D-2D point correspondences.
This function solves the Perspective-3-Point problem, which finds camera pose given exactly 3 point correspondences. Multiple solutions may exist.
Parameters: - objectPoints
: Array of 3D object points (exactly 3 points) - imagePoints
: Array of corresponding 2D image points (exactly 3 points)
- cameraMatrix
: Input camera intrinsic matrix - distCoeffs
: Input distortion coefficients - rvecs
: Output rotation vectors (up to 4 solutions) - tvecs
: Output translation vectors (up to 4 solutions) - flags
: Method for solving P3P problem
solvePnPRefineLM
Refines a pose using Levenberg-Marquardt algorithm.
This function refines the translation and rotation that transform a 3D point expressed in the object coordinate frame to the camera coordinate frame.
Parameters: - objectPoints
: Array of 3D object points - imagePoints
: Array of corresponding 2D image points - cameraMatrix
: Input camera intrinsic matrix
- distCoeffs
: Input distortion coefficients - rvec
: Input/output rotation vector - tvec
: Input/output translation vector - criteria
: Termination criteria for the iterative refinement algorithm
solvePnPRefineVVS
Refines a pose using Virtual Visual Servoing (VVS) algorithm.
Alternative refinement method that can be more robust in certain scenarios.
solvePnPGeneric
Finds an object pose from 3D-2D point correspondences with generic interface.
This function provides a unified interface for different PnP solvers and can return multiple solutions.
Stereo Camera Calibration
calibrateCamera (Overloaded versions)
There are several overloaded versions of calibrateCamera
that provide different interfaces and additional functionality for specific use cases.
calibrateCameraRO
Finds the camera intrinsic and extrinsic parameters from several views of a calibration pattern with enhanced outlier rejection.
This version includes more robust outlier detection and removal mechanisms compared to the standard calibrateCamera
function.
stereoCalibrate
Calibrates a stereo camera setup.
This function finds the intrinsic parameters for each of the two cameras and the relative position and orientation between the two cameras (stereo extrinsic parameters).
Parameters: - objectPoints
: Vector of vectors of 3D calibration pattern points - imagePoints1
: Vector of vectors of 2D image points from first camera - imagePoints2
: Vector of vectors of 2D image points from second camera - cameraMatrix1
: Input/output first camera intrinsic matrix - distCoeffs1
: Input/output first camera distortion coefficients - cameraMatrix2
: Input/output second camera intrinsic matrix - distCoeffs2
: Input/output second camera distortion coefficients - imageSize
: Size of the image used only to initialize camera matrices - R
: Output rotation matrix between coordinate systems of cameras - T
: Output translation vector between coordinate systems of cameras - E
: Output essential matrix - F
: Output fundamental matrix - rvecs
: Output vector of rotation vectors for each pattern view - tvecs
: Output vector of translation vectors for each pattern view - perViewErrors
: Output vector of average reprojection errors for each pattern view - flags
: Different flags for stereo calibration - criteria
: Termination criteria for iterative optimization
stereoRectify
Computes rectification transforms for each head of a calibrated stereo camera.
This function computes the rotation matrices for each camera that make the camera optical axes parallel, which is essential for stereo matching algorithms.
Parameters: - cameraMatrix1
, cameraMatrix2
: Camera intrinsic matrices - distCoeffs1
, distCoeffs2
: Input distortion coefficients for each camera - imageSize
: Size of the image used by stereoCalibrate - R
: Rotation matrix between coordinate systems of the first and second cameras - T
: Translation vector between coordinate systems of cameras - R1
, R2
: Output 3x3 rectification transforms (rotation matrices) for cameras - P1
, P2
: Output 3x4 projection matrices in new rectified coordinate systems - Q
: Output 4×4 disparity-to-depth mapping matrix - flags
: Operation flags - alpha
: Free scaling parameter (0=only valid pixels retained, 1=all source image pixels retained) - newImageSize
: New image resolution after rectification - validPixROI1
, validPixROI2
: Optional rectangles inside rectified images where all pixels are valid
stereoRectifyUncalibrated
Computes a rectification transform for an uncalibrated stereo camera.
This function can be used when you have the fundamental matrix but not the camera calibration parameters.
Parameters: - points1
, points2
: Input point correspondences
- F
: Input fundamental matrix - imgSize
: Size of the image - H1
, H2
: Output rectification homography matrices for first and second images - threshold
: Optional threshold for filtering out the outliers
reprojectImageTo3D
Reprojects a disparity image to 3D space.
This function transforms a single-channel disparity map to a 3-channel image representing a 3D surface.
Parameters: - disparity
: Input single-channel 8-bit unsigned, 16-bit signed, 32-bit signed or 32-bit floating-point disparity image - _3dImage
: Output 3-channel floating-point image of same size as disparity - Q
: 4×4 perspective transformation matrix from stereoRectify - handleMissingValues
: Indicates whether the function should handle missing values - ddepth
: Optional output array depth (default: CV_32F)
computeCorrespondEpilines
For points in an image of a stereo pair, computes the corresponding epilines in the other image.
This function finds the epilines corresponding to the points in one image of a stereo pair in the other image.
Parameters: - points
: Input points (1xN or Nx1 2-channel, CV_32FC2 or vectorwhichImage
: Index of the image (1 or 2) that contains the points - F
: Fundamental matrix - lines
: Output vector of epilines corresponding to the points
convertPointsToHomogeneous
Converts points from Euclidean to homogeneous space.
Parameters: - src
: Input array of N-dimensional points - dst
: Output array of (N+1)-dimensional points
convertPointsFromHomogeneous
Converts points from homogeneous to Euclidean space.
Parameters: - src
: Input array of N-dimensional points in homogeneous coordinates - dst
: Output array of (N-1)-dimensional points
convertPointsHomogeneous
Converts points to/from homogeneous coordinates (deprecated).
This function is deprecated; use convertPointsToHomogeneous
and convertPointsFromHomogeneous
instead.
findFundamentalMat
Calculates a fundamental matrix from the corresponding points in two images.
The fundamental matrix is a 3x3 matrix which relates corresponding points in stereo images.
Parameters: - points1
: Array of N points from the first image - points2
: Array of N points from the second image
- method
: Method for computing fundamental matrix: - FM_7POINT
: 7-point algorithm (requires exactly 7 point pairs) - FM_8POINT
: 8-point algorithm - FM_LMEDS
: Least-Median algorithm
- FM_RANSAC
: RANSAC algorithm - ransacReprojThreshold
: Parameter for RANSAC (maximum distance from point to epipolar line) - confidence
: Confidence level for RANSAC - mask
: Output array of N elements, every element is set to 0 for outliers and 1 for inliers
computeCorrespondEpilines
For points in an image of a stereo pair, computes the corresponding epilines in the other image.
findEssentialMat
Calculates an essential matrix from the corresponding points in two images.
The essential matrix is a simpler form of the fundamental matrix when camera intrinsic parameters are known.
Parameters: - points1
, points2
: Arrays of corresponding points - cameraMatrix
: Camera intrinsic matrix
- method
: Method for computing essential matrix (similar to findFundamentalMat) - prob
: Confidence probability for RANSAC - threshold
: Parameter for RANSAC - mask
: Output mask of inliers
decomposeEssentialMat
Decompose an essential matrix to possible rotations and translation.
This function decomposes the essential matrix E using SVD and returns all possible rotations and translation. Generally 4 possible poses exist for a given E.
Parameters: - E
: Input essential matrix - R1
, R2
: Possible rotation matrices - t
: Possible translation vector
recoverPose
Recovers the relative camera rotation and translation from an essential matrix and corresponding points.
This function determines which of the four possible poses from decomposeEssentialMat
is the correct one by checking which configuration places most points in front of both cameras.
Parameters: - E
: Input essential matrix - points1
, points2
: Input corresponding points - cameraMatrix
: Camera intrinsic matrix - R
: Output rotation matrix - t
: Output translation vector - mask
: Input/output mask of inliers
3D Point Set Registration
estimateTranslation3D
Computes an optimal translation between two 3D point sets.
It computes: \[ \begin{bmatrix} x\\ y\\ z\\ \end{bmatrix} = \begin{bmatrix} X\\ Y\\ Z\\ \end{bmatrix} + \begin{bmatrix} b_1\\ b_2\\ b_3\\ \end{bmatrix} \]
Parameters: - src
: First input 3D point set containing \((X,Y,Z)\) - dst
: Second input 3D point set containing \((x,y,z)\) - out
: Output 3D translation vector \(3 \times 1\) of the form \(\begin{bmatrix} b_1 \\ b_2 \\ b_3 \end{bmatrix}\) - inliers
: Output vector indicating which points are inliers (1-inlier, 0-outlier) - ransacThreshold
: Maximum reprojection error in the RANSAC algorithm to consider a point as an inlier (default: 3) - confidence
: Confidence level, between 0 and 1, for the estimated transformation (default: 0.99)
Values between 0.95 and 0.99 are usually good enough for confidence. Values too close to 1 can slow down estimation significantly. Values lower than 0.8-0.9 can result in an incorrectly estimated transformation.
2D Affine Transformations
estimateAffine2D
Computes an optimal affine transformation between two 2D point sets using robust methods.
The function estimates a 2D affine transformation:
\[ \begin{bmatrix} x\\ y\\ \end{bmatrix} = \begin{bmatrix} a_{11} & a_{12}\\ a_{21} & a_{22}\\ \end{bmatrix} \begin{bmatrix} X\\ Y\\ \end{bmatrix} + \begin{bmatrix} b_1\\ b_2\\ \end{bmatrix} \]
Parameters: - from
: First input 2D point set containing \((X,Y)\) - to
: Second input 2D point set containing \((x,y)\) - inliers
: Output vector indicating which points are inliers (1-inlier, 0-outlier) - method
: Robust method used to compute transformation: - RANSAC
: RANSAC-based robust method (default) - LMEDS
: Least-Median robust method - ransacReprojThreshold
: Maximum reprojection error in RANSAC algorithm (default: 3) - maxIters
: Maximum number of robust method iterations (default: 2000) - confidence
: Confidence level for estimated transformation (default: 0.99) - refineIters
: Maximum iterations of Levenberg-Marquardt refinement (default: 10)
Returns: Output 2D affine transformation matrix \(2 \times 3\): \[ \begin{bmatrix} a_{11} & a_{12} & b_1\\ a_{21} & a_{22} & b_2\\ \end{bmatrix} \]
The computed transformation is refined using the Levenberg-Marquardt method to reduce re-projection error.
Note: RANSAC can handle practically any ratio of outliers but needs a threshold to distinguish inliers from outliers. LMeDS doesn’t need any threshold but works correctly only when there are more than 50% of inliers.
estimateAffinePartial2D
Computes an optimal limited affine transformation with 4 degrees of freedom between two 2D point sets.
This function estimates a 2D affine transformation limited to combinations of translation, rotation, and uniform scaling:
\[\begin{bmatrix} \cos(\theta) \cdot s & -\sin(\theta) \cdot s & t_x \\ \sin(\theta) \cdot s & \cos(\theta) \cdot s & t_y \end{bmatrix}\]
Where \(\theta\) is the rotation angle, \(\lambda\) is the scaling factor, and \(t_x, t_y\) are translations in \(x, y\) axes respectively.
Parameters: - from
: First input 2D point set - to
: Second input 2D point set - inliers
: Output vector indicating which points are inliers - method
: Robust method (RANSAC or LMEDS) - ransacReprojThreshold
: Maximum reprojection error for RANSAC (default: 3) - maxIters
: Maximum number of robust method iterations (default: 2000) - confidence
: Confidence level for estimated transformation (default: 0.99) - refineIters
: Maximum iterations of refinement algorithm (default: 10)
Homography Decomposition
decomposeHomographyMat
Decomposes a homography matrix to rotation(s), translation(s) and plane normal(s).
This function extracts relative camera motion between two views of a planar object and returns up to four mathematical solution tuples of rotation, translation, and plane normal.
Parameters: - H
: Input homography matrix between two images - K
: Input camera intrinsic matrix - rotations
: Array of rotation matrices - translations
: Array of translation matrices
- normals
: Array of plane normal matrices
If the homography H gives the constraint: \[s_i \begin{bmatrix} x'_i \\ y'_i \\ 1 \end{bmatrix} \sim H \begin{bmatrix} x_i \\ y_i \\ 1 \end{bmatrix}\]
Then the tuple of rotations[k] and translations[k] represents a change of basis from the source camera’s coordinate system to the destination camera’s coordinate system.
Note: The translation is normalized by the (typically unknown) depth of the scene, providing direction but with normalized length.
filterHomographyDecompByVisibleRefpoints
Filters homography decompositions based on additional information about visible reference points.
This function filters the output of decomposeHomographyMat
by verifying which homographies are consistent with all visible reference points being in front of the camera.
Parameters: - rotations
: Vector of rotation matrices - normals
: Vector of plane normal matrices - beforePoints
: Vector of visible reference points before homography is applied - afterPoints
: Vector of visible reference points after homography is applied - possibleSolutions
: Vector of int indices representing viable solutions after filtering - pointsMask
: Optional mask representing inliers from findHomography
Stereo Vision
StereoMatcher (Base Class)
The base class for stereo correspondence algorithms.
StereoBM
Class for computing stereo correspondence using the block matching algorithm, introduced and contributed to OpenCV by K. Konolige.
This class implements a block matching algorithm for stereo correspondence, used to compute disparity maps from stereo image pairs. It provides methods to fine-tune parameters such as pre-filtering, texture thresholds, uniqueness ratios, and regions of interest (ROIs).
StereoSGBM
Implements the modified H. Hirschmuller algorithm that differs from the original in several ways:
- Single-pass by default: Considers only 5 directions instead of 8 (set
mode=StereoSGBM::MODE_HH
for full variant) - Block matching: Matches blocks rather than individual pixels (though
blockSize=1
reduces to single pixels) - Simplified cost function: Uses Birchfield-Tomasi sub-pixel metric instead of mutual information
- Enhanced processing: Includes pre- and post-processing steps from StereoBM algorithm
Key parameters: - minDisparity
: Minimum possible disparity value (default: 0) - numDisparities
: Maximum disparity minus minimum disparity (default: 16) - blockSize
: Matched block size (default: 3) - P1
, P2
: Parameters controlling disparity smoothness - disp12MaxDiff
: Maximum allowed difference in left-right disparity check - preFilterCap
: Truncation value for prefiltered image pixels - uniquenessRatio
: Margin in percentage for best vs second-best match - speckleWindowSize
: Maximum size of smooth disparity regions - speckleRange
: Maximum disparity variation within connected components
Image Undistortion
undistort
Transforms an image to compensate for lens distortion.
This function combines initUndistortRectifyMap
(with unity R) and remap
(with bilinear interpolation) to correct radial and tangential lens distortion.
Parameters: - src
: Input (distorted) image - dst
: Output (corrected) image with same size and type as src - cameraMatrix
: Input camera matrix \(A = \begin{bmatrix} f_x & 0 & c_x \\ 0 & f_y & c_y \\ 0 & 0 & 1 \end{bmatrix}\) - distCoeffs
: Input 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]]]])\) - newCameraMatrix
: Camera matrix of distorted image (optional)
Pixels in the destination image with no correspondent pixels in the source are filled with zeros (black).
initUndistortRectifyMap
Computes the undistortion and rectification transformation map for use with remap
.
The function computes joint undistortion and rectification transformation, representing the result as maps for remap
. The undistorted image appears as if captured with a camera using newCameraMatrix
and zero distortion.
Mathematical Process:
For each pixel \((u, v)\) in the destination image, the function computes corresponding coordinates in the source image through this process:
Normalize coordinates: \[x \leftarrow (u - c'_x)/f'_x\] \[y \leftarrow (v - c'_y)/f'_y\]
Apply inverse rectification: \[[X\,Y\,W]^T \leftarrow R^{-1}[x \, y \, 1]^T\] \[x' \leftarrow X/W, \quad y' \leftarrow Y/W\]
Apply distortion model: \[r^2 \leftarrow x'^2 + y'^2\] \[x'' \leftarrow x' \frac{1 + k_1 r^2 + k_2 r^4 + k_3 r^6}{1 + k_4 r^2 + k_5 r^4 + k_6 r^6} + 2p_1 x' y' + p_2(r^2 + 2 x'^2) + s_1 r^2 + s_2 r^4\] \[y'' \leftarrow y' \frac{1 + k_1 r^2 + k_2 r^4 + k_3 r^6}{1 + k_4 r^2 + k_5 r^4 + k_6 r^6} + p_1 (r^2 + 2 y'^2) + 2 p_2 x' y' + s_3 r^2 + s_4 r^4\]
Apply camera matrix: \[\text{map}_x(u,v) \leftarrow x''' f_x + c_x\] \[\text{map}_y(u,v) \leftarrow y''' f_y + c_y\]
Parameters: - cameraMatrix
: Input camera matrix - distCoeffs
: Input distortion coefficients vector - R
: Optional rectification transformation (3x3 matrix) - newCameraMatrix
: New camera matrix - size
: Undistorted image size - m1type
: Type of first output map (CV_32FC1, CV_32FC2, or CV_16SC2) - map1
, map2
: Output maps
initInverseRectificationMap
Computes projection and inverse-rectification transformation map - essentially the inverse of initUndistortRectifyMap
to accommodate stereo-rectification of projectors in projector-camera pairs.
This function is used when working with projector-camera pairs where the projector acts as an “inverse camera”. The projected image appears as a distorted version of the original which, when projected, should visually match the original.
getDefaultNewCameraMatrix
Returns the default new camera matrix, either an exact copy of the input camera matrix or a modified version with centered principal point.
Parameters: - cameraMatrix
: Input camera matrix - imgsize
: Camera view image size in pixels - centerPrincipalPoint
: Whether to center the principal point
When centerPrincipalPoint=true
, returns: \[\begin{bmatrix} f_x & 0 & (\text{imgSize.width}-1) \times 0.5 \\ 0 & f_y & (\text{imgSize.height}-1) \times 0.5 \\ 0 & 0 & 1 \end{bmatrix}\]
Point Undistortion
undistortPoints
Computes ideal point coordinates from observed point coordinates.
This function performs reverse transformation to projectPoints
and operates on sparse point sets rather than raster images.
Mathematical Process:
For each observed point coordinate \((u, v)\):
Normalize: \[x'' \leftarrow (u - c_x)/f_x\] \[y'' \leftarrow (v - c_y)/f_y\]
Undistort: \[(x', y') = \text{undistort}(x'', y'', \text{distCoeffs})\]
Apply rectification: \[[X\,Y\,W]^T \leftarrow R[x' \, y' \, 1]^T\] \[x \leftarrow X/W, \quad y \leftarrow Y/W\]
Apply new camera matrix (if specified): \[u' \leftarrow x f'_x + c'_x\] \[v' \leftarrow y f'_y + c'_y\]
Parameters: - src
: Observed point coordinates (2xN/Nx2 1-channel or 1xN/Nx1 2-channel) - dst
: Output ideal point coordinates - cameraMatrix
: Camera matrix - distCoeffs
: Input distortion coefficients - R
: Rectification transformation (optional) - P
: New camera/projection matrix (optional) - criteria
: Termination criteria for iterative algorithm
undistortImagePoints
Computes undistorted image points position using an iterative algorithm.
Parameters: - src
: Observed points position - dst
: Output undistorted points position - cameraMatrix
: Camera matrix - distCoeffs
: Distortion coefficients - criteria
: Termination criteria (default: 5 iterations with EPS threshold 0.01)
Fisheye Camera Model
The fisheye namespace contains specialized functions for fisheye cameras with very wide fields of view.
Key Differences from Standard Model:
- Uses different distortion model suited for fisheye lenses
- Handles fields of view up to 180° or more
- Specialized calibration and undistortion algorithms
fisheye::projectPoints
Projects points using fisheye model with optional Jacobian computation.
fisheye::distortPoints
Distorts 2D points using fisheye model. Assumes camera intrinsic matrix of undistorted points is identity unless otherwise specified.
fisheye::undistortPoints
Undistorts 2D points using fisheye model with iterative refinement.
fisheye::initUndistortRectifyMap
Computes undistortion and rectification maps for fisheye cameras for use with remap
.
fisheye::undistortImage
Transforms an image to compensate for fisheye lens distortion - combination of fisheye::initUndistortRectifyMap
and remap
.
fisheye::estimateNewCameraMatrixForUndistortRectify
Estimates new camera intrinsic matrix for fisheye undistortion or rectification.
Parameters: - balance
: Sets new focal length between min and max focal length [0,1] - fov_scale
: Divisor for new focal length
fisheye::calibrate
Performs fisheye camera calibration using calibration pattern points.
Calibration Flags: - CALIB_USE_INTRINSIC_GUESS
: Use provided initial values - CALIB_RECOMPUTE_EXTRINSIC
: Recompute extrinsic after each iteration - CALIB_CHECK_COND
: Check validity of condition number - CALIB_FIX_SKEW
: Fix skew coefficient to zero - CALIB_FIX_K1
to CALIB_FIX_K4
: Fix specific distortion coefficients - CALIB_FIX_PRINCIPAL_POINT
: Don’t change principal point - CALIB_FIX_FOCAL_LENGTH
: Don’t change focal length
fisheye::stereoRectify
Stereo rectification for fisheye camera model, computing rectification transforms for stereo camera pairs.
fisheye::stereoCalibrate
Performs stereo calibration for fisheye camera pairs, estimating intrinsic parameters for both cameras and the relative pose between them.
fisheye::solvePnP
Finds object pose from 3D-2D point correspondences for fisheye camera model.
fisheye::solvePnPRansac
Finds object pose using RANSAC scheme for fisheye camera model, providing robustness against outliers.
Summary
Camera calibration is essential for accurate computer vision applications. The functions documented here provide comprehensive tools for:
- Standard perspective cameras: Complete calibration, undistortion, and rectification
- Fisheye cameras: Specialized handling for wide-angle lenses
- Stereo systems: Calibration and rectification for depth estimation
- Robust estimation: RANSAC and other methods for handling outliers
- Geometric transformations: Affine transforms and homography decomposition
Each function is designed to handle specific aspects of the camera calibration pipeline, from initial parameter estimation to final image correction and 3D reconstruction.