[−][src]Module opencv::calib3d
Camera Calibration and 3D Reconstruction
The functions in this section use a so-called pinhole camera model. In this model, a scene view is formed by projecting 3D points into the image plane using a perspective transformation.
or
where:
- are the coordinates of a 3D point in the world coordinate space
- are the coordinates of the projection point in pixels
- is a camera matrix, or a matrix of intrinsic parameters
- is a principal point that is usually at the image center
- are the focal lengths expressed in pixel units.
Thus, if an image from the camera is scaled by a factor, all of these parameters should be scaled (multiplied/divided, respectively) by the same factor. The matrix of intrinsic parameters does not depend on the scene viewed. So, once estimated, it can be re-used as long as the focal length is fixed (in case of zoom lens). The joint rotation-translation matrix is called a matrix of extrinsic parameters. It is used to describe the camera motion around a static scene, or vice versa, rigid motion of an object in front of a still camera. That is, translates coordinates of a point to a coordinate system, fixed with respect to the camera. The transformation above is equivalent to the following (when ):
The following figure illustrates the pinhole camera model.
Real lenses usually have some distortion, mostly radial distortion and slight tangential distortion. So, the above model is extended as:
, , , , , and are radial distortion coefficients. and are tangential distortion coefficients. , , , and , are the thin prism distortion coefficients. Higher-order coefficients are not considered in OpenCV.
The next figures show two common types of radial distortion: barrel distortion (typically ) and pincushion distortion (typically ).
In some cases the image sensor may be tilted in order to focus an oblique plane in front of the camera (Scheimpfug condition). This can be useful for particle image velocimetry (PIV) or triangulation with a laser fan. The tilt causes a perspective distortion of and . This distortion can be modelled in the following way, see e.g. Louhichi07.
where the matrix is defined by two rotations with angular parameter and , respectively,
In the functions below the coefficients are passed or returned as
vector. That is, if the vector contains four elements, it means that . The distortion coefficients do not depend on the scene viewed. Thus, they also belong to the intrinsic camera parameters. And they remain the same regardless of the captured image resolution. If, for example, a camera has been calibrated on images of 320 x 240 resolution, absolutely the same distortion coefficients can be used for 640 x 480 images from the same camera while , , , and need to be scaled appropriately.
The functions below use the above model to do the following:
- Project 3D points to the image plane given intrinsic and extrinsic parameters.
- Compute extrinsic parameters given intrinsic parameters, a few 3D points, and their projections.
- Estimate intrinsic and extrinsic camera parameters from several views of a known calibration pattern (every view is described by several 3D-2D point correspondences).
- Estimate the relative position and orientation of the stereo camera "heads" and compute the rectification transformation that makes the camera optical axes parallel.
Note:
- A calibration sample for 3 cameras in horizontal position can be found at opencv_source_code/samples/cpp/3calibration.cpp
- A calibration sample based on a sequence of images can be found at opencv_source_code/samples/cpp/calibration.cpp
- A calibration sample in order to do 3D reconstruction can be found at opencv_source_code/samples/cpp/build3dmodel.cpp
- A calibration example on stereo calibration can be found at opencv_source_code/samples/cpp/stereo_calib.cpp
- A calibration example on stereo matching can be found at opencv_source_code/samples/cpp/stereo_match.cpp
- (Python) A camera calibration sample can be found at opencv_source_code/samples/python/calibrate.py
Fisheye camera model
Definitions: Let P be a point in 3D of coordinates X in the world reference frame (stored in the matrix X) The coordinate vector of P in the camera reference frame is:
where R is the rotation matrix corresponding to the rotation vector om: R = rodrigues(om); call x, y and z the 3 coordinates of Xc:
The pinhole projection coordinates of P is [a; b] where
Fisheye distortion:
The distorted point coordinates are [x'; y'] where
Finally, conversion into pixel coordinates: The final pixel coordinates vector [u; v] where:
C API
Structs
CirclesGridFinderParameters |
Enums
HandEyeCalibrationMethod | |
SolvePnPMethod |
Constants
Traits
StereoBM | Class for computing stereo correspondence using the block matching algorithm, introduced and contributed to OpenCV by K. Konolige. |
StereoMatcher | The base class for stereo correspondence algorithms. |
StereoSGBM | The class implements the modified H. Hirschmuller algorithm HH08 that differs from the original one as follows: |
Functions
calibrate | Performs camera calibaration |
calibrate_camera | Finds the camera intrinsic and extrinsic parameters from several views of a calibration pattern. |
calibrate_camera_with_stddev | Finds the camera intrinsic and extrinsic parameters from several views of a calibration pattern. |
calibrate_hand_eye | Computes Hand-Eye calibration: inline formula |
calibration_matrix_values | Computes useful camera characteristics from the camera matrix. |
compose_rt | Combines two rotation-and-shift transformations. |
compute_correspond_epilines | For points in an image of a stereo pair, computes the corresponding epilines in the other image. |
convert_points_from_homogeneous | Converts points from homogeneous to Euclidean space. |
convert_points_homogeneous | Converts points to/from homogeneous coordinates. |
convert_points_to_homogeneous | Converts points from Euclidean to homogeneous space. |
correct_matches | Refines coordinates of corresponding points. |
decompose_essential_mat | Decompose an essential matrix to possible rotations and translation. |
decompose_homography_mat | Decompose a homography matrix to rotation(s), translation(s) and plane normal(s). |
decompose_projection_matrix | Decomposes a projection matrix into a rotation matrix and a camera matrix. |
distort_points | Distorts 2D points using fisheye model. |
draw_chessboard_corners | Renders the detected chessboard corners. |
draw_frame_axes | Draw axes of the world/object coordinate system from pose estimation. ## See also solvePnP |
estimate_affine_2d | Computes an optimal affine transformation between two 2D point sets. |
estimate_affine_3d | Computes an optimal affine transformation between two 3D point sets. |
estimate_affine_partial_2d | Computes an optimal limited affine transformation with 4 degrees of freedom between two 2D point sets. |
estimate_new_camera_matrix_for_undistort_rectify | Estimates new camera matrix for undistortion or rectification. |
filter_homography_decomp_by_visible_refpoints | Filters homography decompositions based on additional information. |
filter_speckles | Filters off small noise blobs (speckles) in the disparity map |
find4_quad_corner_subpix | finds subpixel-accurate positions of the chessboard corners |
find_chessboard_corners | Finds the positions of internal corners of the chessboard. |
find_circles_grid | Finds centers in the grid of circles. |
find_circles_grid_params | Finds centers in the grid of circles. |
find_essential_mat | Calculates an essential matrix from the corresponding points in two images. |
find_essential_mat_matrix | Calculates an essential matrix from the corresponding points in two images. |
find_fundamental_mat | Calculates a fundamental matrix from the corresponding points in two images. |
find_homography | Finds a perspective transformation between two planes. |
find_homography_ext | Finds a perspective transformation between two planes. |
fisheye_init_undistort_rectify_map | Computes undistortion and rectification maps for image transform by cv::remap(). If D is empty zero distortion is used, if R or P is empty identity matrixes are used. |
fisheye_project_points | Projects points using fisheye model |
fisheye_stereo_calibrate | Performs stereo calibration |
fisheye_stereo_rectify | Stereo rectification for fisheye camera model |
fisheye_undistort_image | Transforms an image to compensate for fisheye lens distortion. |
fisheye_undistort_points | Undistorts 2D points using fisheye model |
get_optimal_new_camera_matrix | Returns the new camera matrix based on the free scaling parameter. |
get_valid_disparity_roi | computes valid disparity ROI from the valid ROIs of the rectified images (that are returned by cv::stereoRectify()) |
init_camera_matrix_2d | Finds an initial camera matrix from 3D-2D point correspondences. |
mat_mul_deriv | Computes partial derivatives of the matrix product for each multiplied matrix. |
project_points | Projects 3D points to an image plane. |
recover_pose | Recover relative camera rotation and translation from an estimated essential matrix and the corresponding points in two images, using cheirality check. Returns the number of inliers which pass the check. |
recover_pose_camera | Recover relative camera rotation and translation from an estimated essential matrix and the corresponding points in two images, using cheirality check. Returns the number of inliers which pass the check. |
recover_pose_camera_with_points | Recover relative camera rotation and translation from an estimated essential matrix and the corresponding points in two images, using cheirality check. Returns the number of inliers which pass the check. |
rectify3_collinear | computes the rectification transformations for 3-head camera, where all the heads are on the same line. |
reproject_image_to_3d | Reprojects a disparity image to 3D space. |
rodrigues | Converts a rotation matrix to a rotation vector or vice versa. |
rq_decomp3x3 | Computes an RQ decomposition of 3x3 matrices. |
sampson_distance | Calculates the Sampson Distance between two points. |
solve_p3p | Finds an object pose from 3 3D-2D point correspondences. |
solve_pnp | Finds an object pose from 3D-2D point correspondences. This function returns the rotation and the translation vectors that transform a 3D point expressed in the object coordinate frame to the camera coordinate frame, using different methods: |
solve_pnp_generic | Finds an object pose from 3D-2D point correspondences. This function returns a list of all the possible solutions (a solution is a <rotation vector, translation vector> couple), depending on the number of input points and the chosen method: |
solve_pnp_ransac | Finds an object pose from 3D-2D point correspondences using the RANSAC scheme. |
solve_pnp_refine_lm | Refine a pose (the translation and the rotation that transform a 3D point expressed in the object coordinate frame to the camera coordinate frame) from a 3D-2D point correspondences and starting from an initial solution. |
solve_pnp_refine_vvs | Refine a pose (the translation and the rotation that transform a 3D point expressed in the object coordinate frame to the camera coordinate frame) from a 3D-2D point correspondences and starting from an initial solution. |
stereo_calibrate_camera | C++ default parameters |
stereo_calibrate_camera_with_errors | Calibrates the stereo camera. |
stereo_rectify_camera | Computes rectification transforms for each head of a calibrated stereo camera. |
stereo_rectify_uncalibrated | Computes a rectification transform for an uncalibrated stereo camera. |
triangulate_points | Reconstructs points by triangulation. |
validate_disparity | validates disparity using the left-right check. The matrix "cost" should be computed by the stereo correspondence algorithm |