A Python implementation of Zhang's camera calibration technique using a planar checkerboard pattern. This project provides tools for estimating both intrinsic and extrinsic camera parameters through checkerboard corner detection, homography computation, and non-linear optimization.
- Automatic checkerboard corner detection and sub-pixel refinement
- Intrinsic camera parameter estimation (focal length, principal point)
- Extrinsic parameter computation (rotation, translation) for each calibration image
- Lens distortion correction (radial distortion coefficients k₁, k₂)
- Visualization tools for calibration quality assessment
- Image undistortion capabilities
The calibration pipeline follows these key steps:
-
Image Acquisition and Corner Detection
- Process multiple JPEG calibration images
- Automatic checkerboard corner detection using OpenCV
- Sub-pixel corner refinement for improved accuracy
-
Initial Parameter Estimation
- Homography computation using Direct Linear Transform (DLT)
- Intrinsic parameter extraction from homography constraints
- Per-image extrinsic parameter estimation (R, t)
-
Non-Linear Parameter Refinement
- Joint optimization of all parameters
- Minimization of reprojection error
- Estimation of lens distortion coefficients
- Bundle adjustment for improved accuracy
-
Visualization and Validation
- Image undistortion using calibrated parameters
- Overlay of detected vs. reprojected corners
- Reprojection error visualization and statistics
- Python 3.x
- OpenCV
- NumPy
- SciPy
# Clone the repository
git clone https://github.com/yourusername/camera-calibration.git
cd camera-calibration
# Install required packages
pip install opencv-python numpy scipy
# Example code snippet for running calibration
from calibration import CameraCalibration
# Initialize calibrator
calibrator = CameraCalibration()
# Add calibration images
calibrator.add_images('path/to/calibration/images/*.jpg')
# Run calibration
calibrator.calibrate()
# Get calibration results
K, dist_coeffs = calibrator.get_parameters()
# Undistort an image
undistorted = calibrator.undistort_image(image)
![]() |
![]() |
Checkerboard 1 | Checkerboard 2 |
![]() |
![]() |
Reprojection 1 | Reprojection 2 |
![]() |
![]() |
Undistorted Image 1 | Undistorted Image 2 |
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
If you use this implementation in your research, please cite:
@article{zhang2000flexible,
title={A flexible new technique for camera calibration},
author={Zhang, Zhengyou},
journal={IEEE Transactions on pattern analysis and machine intelligence},
volume={22},
number={11},
pages={1330--1334},
year={2000},
publisher={IEEE}
}