Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Fisheye lens calibration using OpenCV returning zero valued distortion matrix

I am doing all the usual for calibrating a fisheye lens, I have 22 images that return true using the findChessboardCorners() function, I concatenate the points into a vector<vector<Point2f>> which I use for the calibrate function.

I have altered my code which was using the standard model (worked flawlessly) to accommodate the fisheye model provided by OpenCV under the fisheye:: namespace and now the fisheye::calibrate() function returns a camera matrix with valid results. However, the distortion Mat that is returned is just full of zeros.

Here are the main components of the code:

Populating the `vector<Point3f>` object:
vector<vector<Point2f>> imagePoints;
vector<vector<Point3f>> objectPoints;
vector<Point3f> obj;
int boardCols = 15;
int boardRows = 9

for(int j=0;j<boardCols*boardRows;j++)
    obj.push_back(Point3f(j/boardCols, j%boardCols, 0.0f));

Finding the corners of the checkerboard:

QString dir = ""; // Path to checkerboard images

QDirIterator it(dir, QDir::Files, QDirIterator::Subdirectories);

while (it.hasNext())
{

    Mat inputImage = imread(it.next().toStdString());

    vector<Point2f> ptvec;

    bool found = findChessboardCorners( inputImage, Size(boardCols,boardRows), ptvec,  CV_CALIB_CB_ADAPTIVE_THRESH | CV_CALIB_CB_FILTER_QUADS);

    if(found==true){
        objectPoints.push_back(obj);
        imagePoints.push_back(ptvec);
    }
}

Trying to extract the distortion and camera matrices:

Mat distCoeffs = Mat::ones(4, 1, CV_64F);
Mat cameraMatrix = Mat::eye(3, 3, CV_64F);
vector<Mat> rvecs, tvecs;

double rms = fisheye::calibrate(objectPoints, imagePoints, imageSize, cameraMatrix, distCoeffs, rvecs, tvecs, fisheye::CALIB_FIX_SKEW | fisheye::CALIB_RECOMPUTE_EXTRINSIC);

Fisheye lens calibration using OpenCV returning zero valued distortion matrix

I am doing all the usual for calibrating a fisheye lens, I have 22 images that return true using the findChessboardCorners() function, I concatenate the points into a vector<vector<Point2f>> which I use for the calibrate function.

I have altered my code which was using the standard model (worked flawlessly) to accommodate the fisheye model provided by OpenCV under the fisheye:: namespace and now the fisheye::calibrate() function returns a camera matrix with valid results. However, the distortion Mat that is returned is just full of zeros.

Here are the main components of the code:

Populating the vector<Point3f> object:

Populating the `vector<Point3f>` object:
vector<vector<Point2f>> imagePoints;
vector<vector<Point3f>> objectPoints;
vector<Point3f> obj;
int boardCols = 15;
int boardRows = 9

for(int j=0;j<boardCols*boardRows;j++)
    obj.push_back(Point3f(j/boardCols, j%boardCols, 0.0f));

Finding the corners of the checkerboard:

QString dir = ""; // Path to checkerboard images

QDirIterator it(dir, QDir::Files, QDirIterator::Subdirectories);

while (it.hasNext())
{

    Mat inputImage = imread(it.next().toStdString());

    vector<Point2f> ptvec;

    bool found = findChessboardCorners( inputImage, Size(boardCols,boardRows), ptvec,  CV_CALIB_CB_ADAPTIVE_THRESH | CV_CALIB_CB_FILTER_QUADS);

    if(found==true){
        objectPoints.push_back(obj);
        imagePoints.push_back(ptvec);
    }
}

Trying to extract the distortion and camera matrices:

Mat distCoeffs = Mat::ones(4, 1, CV_64F);
Mat cameraMatrix = Mat::eye(3, 3, CV_64F);
vector<Mat> rvecs, tvecs;

double rms = fisheye::calibrate(objectPoints, imagePoints, imageSize, cameraMatrix, distCoeffs, rvecs, tvecs, fisheye::CALIB_FIX_SKEW | fisheye::CALIB_RECOMPUTE_EXTRINSIC);