Overview
From opencv2/calib3d.hpp:54-277, detailed mathematical background:The functions in this section use a pinhole camera model with lens distortion for camera calibration, stereo calibration and rectification, 3D reconstruction from stereo, and pose estimation.
Camera Calibration
Determine intrinsic and extrinsic camera parameters
Stereo Vision
Calibrate stereo camera pairs and rectify images
3D Reconstruction
Reconstruct 3D points from multiple views
Pose Estimation
Estimate object position and orientation
Pinhole Camera Model
From calib3d.hpp:64-72, the fundamental projection equation: [ s \begin u \ v \ 1 \end = \mathbf \begin \mathbf | \mathbf \end \begin X_w \ Y_w \ Z_w \ 1 \end ] Where:- A - Camera intrinsic matrix (focal length, principal point)
- R - Rotation matrix (3x3)
- t - Translation vector (3x1)
- (X_w, Y_w, Z_w) - 3D world coordinates
- (u, v) - 2D image coordinates
Camera Intrinsic Matrix
From calib3d.hpp:79-83: [ \mathbf = \begin f_x & 0 & c_x \ 0 & f_y & c_y \ 0 & 0 & 1 \end ]- f_x, f_y - Focal lengths in pixel units
- c_x, c_y - Principal point (optical center)
Lens Distortion
From calib3d.hpp:225-264, real lenses have distortion:Distortion Coefficients
- k1, k2, k3, k4, k5, k6 - Radial distortion coefficients
- p1, p2 - Tangential distortion coefficients
- s1, s2, s3, s4 - Thin prism distortion coefficients
Distortion Model
From calib3d.hpp:228-244: Where ( r^2 = x’^2 + y’^2 )Camera Calibration
Example from samples/cpp/calibration.cpp:Chessboard Calibration
Calibration Flags
Undistortion
Undistort Images
Remap for Efficiency
Stereo Calibration
Calibrate Stereo Pair
Stereo Rectification
Disparity and Depth
Stereo Matching
Reconstruct 3D Points
Pose Estimation
solvePnP - Estimate Camera Pose
PnP Methods
Draw 3D Axes
Homography
Find Homography
Decompose Homography
Triangulation
Best Practices
Calibration Quality:
- Use at least 10-20 images from different angles
- Cover the entire image area with calibration pattern
- RMS error should be < 1 pixel for good calibration
- Check reprojection errors for outliers
Calibration Pattern:
- Chessboard is most common and reliable
- Ensure pattern is perfectly flat
- Use high-quality printing
- Good lighting without glare
Stereo Vision:
- Baseline (distance between cameras) affects depth range
- Larger baseline = better depth accuracy at distance
- Cameras should be well-aligned (< 5° rotation)
- Synchronized capture for moving scenes
Performance:
Related Modules
- Features 2D - Feature detection for matching
- Image Processing - Image transformations
- Video Analysis - Optical flow for tracking
Source Reference
Main header:~/workspace/source/modules/calib3d/include/opencv2/calib3d.hpp
Examples:
samples/cpp/calibration.cpp- Camera calibrationsamples/cpp/stereo_calib.cpp- Stereo calibrationsamples/cpp/stereo_match.cpp- Stereo matching
