darglein / ADOP

MIT License
2.02k stars 197 forks source link

is the camera model not the real default in COLMAP? #58

Closed cduguet closed 2 years ago

cduguet commented 2 years ago

In the README, it says that (other than Fisheye) the supported camera model is Pinhole/Distortion and that it's the same as the default in COLMAP. From what I see, it contains the distortion parameters (k1, k2, k3, k4, k5, k6, p1, p2) in adition to the pinhole parameters (fx, fy, cx, cy, s). The closest OpenCV equivalent for these parameters is FullOpenCVCameraModel. However, COLMAP uses SIMPLE_RADIAL as its default model. SIMPLE_RADIAL only uses (f, cx, cy, k). It seems that Metashape also uses something similar to the FullOpenCV model, with more tangential distortion only.

Should I be safe to assume that you actually refer to a FullOpenCVCameraModel instead of a SimpleRadialCameraModel?

darglein commented 2 years ago

Hey, ADOP uses a more general Pinhole/Distortion model with 8 Parameters. It can be used for all of COLMAPS camera models. See here: https://github.com/darglein/saiga/blob/f3212a3ae8037ca23f69f1d6855fc889866c83e4/src/saiga/vision/util/ColmapReader.h

This is how you convert from COLMAP->ADOP

All other parameters should be 0.

 case 1:
                {
                    // Pinhole
                    // fx, fy, cx, cy
                    std::array<double, 4> coeffs;
                    file >> coeffs;
                    c.K.fx = coeffs[0];
                    c.K.fy = coeffs[1];
                    c.K.cx = coeffs[2];
                    c.K.cy = coeffs[3];
                    break;
                }
                case 2:
                {
                    // Simple Radial
                    // f, cx, cy, k1
                    std::array<double, 4> coeffs;
                    file >> coeffs;
                    c.K.fx   = coeffs[0];
                    c.K.fy   = coeffs[0];
                    c.K.cx   = coeffs[1];
                    c.K.cy   = coeffs[2];
                    c.dis.k1 = coeffs[3];
                    break;
                }
                case 3:
                {
                    // RADIAL
                    // f, cx, cy, k1, k2
                    std::array<double, 5> coeffs;
                    file >> coeffs;
                    c.K.fx   = coeffs[0];
                    c.K.fy   = coeffs[0];
                    c.K.cx   = coeffs[1];
                    c.K.cy   = coeffs[2];
                    c.dis.k1 = coeffs[3];
                    c.dis.k2 = coeffs[4];
                    break;
                }
                case 4:
                {
                    // OPENCV
                    // fx, fy, cx, cy,   k1, k2, p1, p2
                    std::array<double, 8> coeffs;
                    file >> coeffs;
                    c.K.fx = coeffs[0];
                    c.K.fy = coeffs[1];
                    c.K.cx = coeffs[2];
                    c.K.cy = coeffs[3];

                    c.dis.k1 = coeffs[4];
                    c.dis.k2 = coeffs[5];
                    c.dis.p1 = coeffs[6];
                    c.dis.p2 = coeffs[7];
                    break;
                }

                case 6:
                {
                    // FULL_OPENCV
                    // fx, fy, cx, cy,   k1, k2, p1, p2,   k3, k4, k5, k6
                    std::array<double, 12> coeffs;
                    file >> coeffs;
                    c.K.fx = coeffs[0];
                    c.K.fy = coeffs[1];
                    c.K.cx = coeffs[2];
                    c.K.cy = coeffs[3];

                    c.dis.k1 = coeffs[4];
                    c.dis.k2 = coeffs[5];
                    c.dis.p1 = coeffs[6];
                    c.dis.p2 = coeffs[7];

                    c.dis.k3 = coeffs[8];
                    c.dis.k4 = coeffs[9];
                    c.dis.k5 = coeffs[10];
                    c.dis.k6 = coeffs[11];
                    break;
                };