chaehyeonsong / discocal

150 stars 21 forks source link

Unbiased Estimator for Distorted Conics in Camera Calibration (CVPR24, highlight)

For decades, the checkerboard pattern has been the go-to method for camera calibration, providing only pixel-level precision. But what if we could improve accuracy even further? This paper reveals the power of the circular pattern: a game-changer offering subpixel precision to meet challenges even from unconventional visual sensors.

[Paper][Video][OpenCV Webinar][BibTex]

News

The core limitation for conic in camera calibration

Sub-pixel accuracy and detection robustness are virtues of the conic features. But why do we use a checkerboard, not a circular pattern?

:cry: Conic is not conic anymore under distortion!!

As shown below, the circle center is not projected to the centroid of the distorted ellipse under perspective transformation and distortion.

Without considering geometery of the distorted ellipse, existing circular pattern-based calibration methods are biased, which leads low calibration accuracy than a checkerboard pattern.

:pushpin: Our unbiased estimator completes the missing piece in the conic-based calibration pipeline


How to use

0. Projection model

We assume pinhole camera model with radial distortion.

\begin{aligned}
s\begin{bmatrix}
x_n\\ y_n \\ 1
\end{bmatrix} &= \begin{bmatrix} \boldsymbol{r}_1 & \boldsymbol{r}_2 & \boldsymbol{r}_3 & \boldsymbol{t} 
\end{bmatrix}\begin{bmatrix}
x_w\\ y_w \\ z_w \\ 1
\end{bmatrix} \\
k &= 1+ \sum_{i=1}^{n_d}k_i(x_n^2+y_n^2)^i\\
\begin{bmatrix}
u\\ v
\end{bmatrix} &= \begin{bmatrix}
f_x & \eta & c_x \\
0 & f_y & c_y
\end{bmatrix} \begin{bmatrix}
kx_n \\ ky_n \\ 1
\end{bmatrix}
\end{aligned} 

Calibration results: $f_x, f_y, c_x, c_y, \eta, k_1, k_2, ... k_n$

Q. How do you undisort images using this model?

Option 1) Use cv::undistort function(Only n_d <=3)

Our model is compatible to OpenCV pin-hole camera model. Set p1 and p2 as zero.

distcoeff=(cv::Mat1d(1, 5) << k_1, k_2, 0., 0., k_3);
cv::initUndistortRectifyMap(camera_matrix, distcoeff, cv::Mat(), camera_matrix, imageSize, CV_32FC1, mapx, mapy);
cv::remap(image,undist_image, mapx, mapy, cv::INTER_LINEAR);

Option 2) Use Imagehandler class (General case)

We provide a class that has an "undistort" function. This class can deal with n_d>3 cases. Please refer to the “CImagehander.cpp” files for details.

Imagehandler imagehandler(width, height, total_params, n_d);
cv::Mat undist_image = imagehandler.undist(image);

1. Calibration Target

Our method needs a planer white board on which black circle grid patterns are printed. You can easily design these patterns in this site.

Previous methods prefer to reduce the size of the circles to minimize bias, but our method is not limited to this. In fact, the larger the circles, the more accurate the measurements.

Q. How to decide the number of cicles and the radius size? The larger the radius of the circle, the more accurate the observations become. The greater the number of circles, the more observations you have, leading to increased robustness. Since these two values are in a trade-off relationship within a limited area, adjust them appropriately. It is recommended that every circle contains more than 400 pixels in images and not to exceed 7x5 circles.

2. Dependency

Option 1) Install bellow packages

Option 2) Use docker

(Recommended) Build a docker image using the dockerfile.

docker build -t chaehyeonsong/discocal .  -f dockerfile

(Only for Ubuntu) or use official docker image.

docker pull chaehyeonsong/discocal:latest

3. Bulid and Run

## Build
cd [your path]/discocal
mkdir build
cd build
cmake ..
make

## Run
./main.out [n_x] [n_y] [n_d] [img_dir_path] [radius(m)] [distance(m)]
(ex) ./main.out 4 3 3 ../sample_imgs/rgb12/ 0.035 0.09
(ex) ./main.out 4 3 4 ../sample_imgs/tir12/ 0.03 0.09

:open_mouth: Caution: Check detection results!

To get high-quality results, plz check all pixels in the circle are correctly detected like this.

If you don’t want to check images, turn off the “check_detection_results” option in "main.cpp".

Parameters(for experts):


Application: Thermal Camera calibration

We can leverage the detection robustness of the circular patterns, particularly for unconventional cameras, such as thermal cameras.

BibTex

@INPROCEEDINGS{chsong-2024-cvpr,  
    author    = {Song, Chaehyeon and Shin, Jaeho and Jeon, Myung-Hwan and Lim, Jongwoo and Kim, Ayoung},
    title     = {Unbiased Estimator for Distorted Conics in Camera Calibration},
    booktitle = {IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)},
    month     = {June},
    year      = {2024},
    pages     = {373-381}
}

Lisence

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.