Skip to main content
The Camera Calibration and 3D Reconstruction (calib3d) module provides algorithms for camera calibration, stereo vision, 3D reconstruction, and geometric transformations for computer vision applications.

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: x=x1+k1r2+k2r4+k3r61+k4r2+k5r4+k6r6+2p1xy+p2(r2+2x2)x'' = 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 + 2x'^2) y=y1+k1r2+k2r4+k3r61+k4r2+k5r4+k6r6+p1(r2+2y2)+2p2xyy'' = 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 + 2y'^2) + 2p_2 x'y' 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:

Source Reference

Main header: ~/workspace/source/modules/calib3d/include/opencv2/calib3d.hpp Examples:
  • samples/cpp/calibration.cpp - Camera calibration
  • samples/cpp/stereo_calib.cpp - Stereo calibration
  • samples/cpp/stereo_match.cpp - Stereo matching