- Detect chessboard corners in multiple calibration images
- Calibrate the camera to find intrinsic parameters and distortion coefficients
- Undistort images using the calibration results
- Visualize the results to verify calibration quality
Run the Camera Calibration Demo
Open the camera calibration notebook in Google Colab to run the calibration process.
Camera Calibration Process
What happens during calibration:
-
Camera Calibration: Use
cv2.calibrateCamera()to find:- Camera matrix (K): Contains focal lengths (fx, fy) and principal point (cx, cy)
- Distortion coefficients: Correct for lens distortion (radial and tangential)
- Rotation/translation vectors: Camera pose for each calibration view
- Image Undistortion: Apply the calibration to remove lens distortion from images
- Results Visualization: Compare original vs. undistorted images
OpenCV Functions for Camera Calibration
initCameraMatrix2D
Finds an initial camera intrinsic matrix from 3D-2D point correspondences. This function provides a good initial estimate for camera calibration by finding the camera matrix that minimizes reprojection error for a set of calibration points. Parameters:objectPoints: Vector of vectors of 3D calibration pattern pointsimagePoints: Vector of vectors of corresponding 2D image pointsimageSize: Image size used only to initialize camera intrinsic matrixaspectRatio: If zero, both fx and fy are estimated independently. Otherwise, fx = fy * aspectRatio
findChessboardCorners
Finds the positions of internal corners of the chessboard. This function detects the positions of internal corners in a chessboard calibration pattern. Parameters:image: Source chessboard view (8-bit grayscale or color)patternSize: Number of inner corners per chessboard row and columncorners: Output array of detected cornersflags: Various operation flags:CALIB_CB_ADAPTIVE_THRESH: Use adaptive thresholdingCALIB_CB_NORMALIZE_IMAGE: Normalize image gammaCALIB_CB_FILTER_QUADS: Use additional criteria to filter out false quadsCALIB_CB_FAST_CHECK: Run fast check to quickly determine if pattern is present
findChessboardCornersSB
Finds the positions of internal corners using a sector-based approach. This is an improved version of corner detection that’s more robust to lighting conditions and partial occlusions.estimateChessboardSharpness
Estimates the sharpness of a detected chessboard. This function can be used to assess the quality of calibration images by measuring how sharp the chessboard pattern appears. Parameters:image: Source chessboard viewpatternSize: Size of the chessboard patterncorners: Chessboard corners detected by findChessboardCornersrise_distance: Rise distance 0.8 means 10% … 90% of the final signal strengthvertical: By default, the function checks the vertical edges of the chessboard
drawChessboardCorners
Renders the detected chessboard corners. This function is useful for visualizing detected corners and verifying the correctness of corner detection. Parameters:image: Destination image (color or grayscale, 8-bit)patternSize: Number of inner corners per chessboard row and columncorners: Array of detected cornerspatternWasFound: Parameter indicating whether complete board was found
drawFrameAxes
Draw axes of the world/object coordinate system from pose estimation. This function draws the 3D coordinate system axes to visualize object pose. Parameters:image: Input/output imagecameraMatrix: Input camera intrinsic matrixdistCoeffs: Input distortion coefficientsrvec: Rotation vectortvec: Translation vectorlength: Length of the drawn axes in the same unit as tvecthickness: Line thickness of the drawn axes
findCirclesGrid
Finds centers in the grid of circles. This function detects a grid of circles pattern, which is an alternative to chessboard patterns for camera calibration. Parameters:image: Grid view of circles (8-bit grayscale or color)patternSize: Number of circles per row and columncenters: Output array of detected centersflags: Various operation flags:CALIB_CB_SYMMETRIC_GRID: Grid is symmetricCALIB_CB_ASYMMETRIC_GRID: Grid is asymmetricCALIB_CB_CLUSTERING: Use k-means clustering to find grid
calibrateCamera
Finds the camera intrinsic and extrinsic parameters from several views of a calibration pattern. This is the main camera calibration function that estimates all camera parameters. Parameters:objectPoints: Vector of vectors of 3D calibration pattern pointsimagePoints: Vector of vectors of corresponding 2D image pointsimageSize: Size of the image used only to initialize camera intrinsic matrixcameraMatrix: Input/output 3x3 camera intrinsic matrixdistCoeffs: Input/output vector of distortion coefficientsrvecs: Output vector of rotation vectors for each pattern viewtvecs: Output vector of translation vectors for each pattern viewflags: Different flags for calibration:CALIB_USE_INTRINSIC_GUESS: cameraMatrix contains valid initial valuesCALIB_FIX_PRINCIPAL_POINT: Principal point is not changedCALIB_FIX_ASPECT_RATIO: Fix fx/fy ratioCALIB_ZERO_TANGENT_DIST: Tangential distortion coefficients are set to zerosCALIB_FIX_K1,CALIB_FIX_K2, etc.: Fix specific distortion coefficients
criteria: Termination criteria for iterative optimization algorithm

