We use a simple checkerboard to obtain camera intrinsic properties and distortion parameters.
It's advised to create a conda environment first.
conda create -n camera python=3.8
conda init
exec zsh
conda activate camera
git clone https://github.com/yashdeep01/CameraCalibrationCheckerboard.git
cd CameraCalibrationCheckerboard/
pip install -r requirements.txt
Cloning the repo must give you such a directory tree
├── CameraCalibrationCheckerboard
│ ├── README.md
│ ├── calibrate.py
│ ├── checkerboard/
│ ├── extract_frames.py
│ ├── frames/
│ └── requirements.txt
Before running calibration on your machine, you must click some pictures of the chekcerboard given as pattern.pdf
here. Follow the steps:
- Print the checkerboard pattern on an A4 sheet.
- Glue the pattern on a flat surface, like a wall, cardboard, etc.
- Keep the surface still and click its photos from various angles. Click at least 50 images. Alternatively, you could also record a video by moving the camera around the surface at various angles and distance.
- Save the photos (or video) on your machine.
- If you clicked pictures, save the clicked pictures in
./frames/
directory of the cloned repo. - Else, if you recorded a video, run this command to extract frames from the video and automatically save in
./frames/
directory:
python extract_frames.py --video /path/to/video
- If you clicked pictures, save the clicked pictures in
python calibrate.py
Aruco markers drawn on the checkerboard photos are stored in ./checkerboard/
directory.
The results of the calibration command are present in ./results/
directory.
./results/mtx.csv
contains the3x3
camera intrinsic matrix (denoted by K)../results/dist.csv
contains the distortion parameters k1, k2, k3... which are responsible for the fish-eye effect in the images captured by the camera../results/rvecs.csv
contains the rotation vectors R of the camera extrinsic matrix../results/tvecs.csv
contains the translation vectors t of the camera extrinsic matrix.
This package allows users many flexibilities while performing calibration. Running python calibrate.py --help
gives the following output on shell:
% python calibrate.py --help
usage: calibrate.py [-h] [-p PATH] [-r ROW] [-c COL]
Calibrate a camera using checkerboard
optional arguments:
-h, --help show this help message and exit
-p PATH, --path PATH Path of the images directory
-r ROW, --row ROW No. of rows of the checkerboard
-c COL, --col COL No. of cols of the checkerboard