This repository contains the code for calibrating a monocular camera using a chessboard pattern. The code is written in Python and uses OpenCV for camera calibration.
A camera is a fundamental tool used across various domains, including robotics, surveillance, and entertainment. To leverage a camera effectively as a visual sensor, understanding its parameters through camera calibration is crucial.
Camera calibration is the process of estimating a camera's intrinsic and extrinsic parameters to establish a precise relationship between real-world 3D points and their corresponding 2D projections (pixels) in captured images.
-
Internal Parameters: represented in the form of the intrinsic matrix (
K
), which includes:- Focal length
- Optical center
- Radial distortion coefficients
-
External Parameters:
- Rotation matrix (
R
) - Translation vector (
t
)
- Rotation matrix (
The calibration workflow typically involves:
- Capturing images of a known calibration pattern (e.g., checkerboard) from various viewpoints.
- Detecting and refining the corners of the calibration pattern in the images.
- Using the detected 2D-3D correspondences to estimate the camera's intrinsic matrix (
K
), rotation matrix (R
), and translation vector (t
).
- Clone the repository
- Create a virtual environment using conda:
conda create -n camera_calibration python=3.8
- Activate the virtual environment:
conda activate camera_calibration
- Install the required packages:
pip install -r requirements.txt
- Capture images of the chessboard pattern from different angles and distances. Feel free to use the images provided in the data/images folder.
- Run the following command to calibrate the camera:
python src/main.py --chessboard_size "24,17" --square_size 0.015
- this will result in the following outputs:
- The camera matrix and distortion coefficients will be saved in the data/params folder.
- The undistorted images will be saved in the data/undistorted folder.
- The chessboard corners will be drawn on the images and saved in the data/corners folder.
The utilized images are taken from the this repository. I would like to thank the author for providing the images.
This project is licensed under the MIT License - see the LICENSE file for details.