rameau-fr/MC-Calib

Fisheye distortion coefficient format

shreyas23 opened this issue · 2 comments

Hey @rameau-fr hope you're doing well!

I'm calibrating a set of fisheye cameras and initializing K with some nominal known values while setting the distortion coefficients to 0. I noticed that k4 is always 0 after optimization.

After brief investigation it seems like there's a discrepancy in the format and order of the distortion vector:

via OpenCV in fisheye::calibrate() : Output vector of distortion coefficients (k1, k2, k3, k4).

// fx,fy,u0,v0,k1,k2,k3,k4 (Kannala)

setDistortionVector:
if (distortion_model_ == 1) {
intrinsics_[4] = distortion_vector.at<double>(0);
intrinsics_[5] = distortion_vector.at<double>(1);
intrinsics_[8] = distortion_vector.at<double>(2);
intrinsics_[6] = distortion_vector.at<double>(3);

getDistortionVector:
else if (distortion_model_ == 1) {
cv::Mat distortion_vector = cv::Mat(1, 4, CV_64F, cv::Scalar(0));
distortion_vector.at<double>(0) = intrinsics_[4];
distortion_vector.at<double>(1) = intrinsics_[5];
distortion_vector.at<double>(4) = intrinsics_[8];
distortion_vector.at<double>(2) = intrinsics_[6];

but then during optimization:

const T k1 = Intrinsics[4]; //
const T k2 = Intrinsics[5]; //
const T k3 = Intrinsics[6]; //
const T k4 = Intrinsics[7]; //

If I understand correctly, the following changes should be made:

setDistortionVector:
intrinsics_[6] = distortion_vector.at<double>(2);
intrinsics_[7] = distortion_vector.at<double>(3);

getDistortionVector:
distortion_vector.at<double>(3) = intrinsics_[7]

Let me know if this sounds right to you.

Hello @shreyas23, I do not know how to thank you enough for reporting it !!
I think you are right. I will double-check this issue with @BAILOOL, and we will make the change as soon as possible. It is quite a big bug here. It might also be the reason why some persons calibrating large field-of-view cameras were facing issues during calibration.
Please, keep me in touch if you make some tests with your modified version of the code.

My pleasure! I did run some tests while fixing it on my end and seemingly had better convergence. I can run some comparisons when I get a chance but the effects likely aren't significant in my scenario as my FoV is not too high.