Ask Your Question

Fisheye lens calibration using OpenCV returning zero valued distortion matrix

asked 2017-03-29 08:31:15 -0500

JackGold1 gravatar image

updated 2017-03-29 09:10:58 -0500

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(;

    vector<Point2f> ptvec;

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


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);
edit retag flag offensive close merge delete


Link to checkerboard images:

JackGold1 gravatar imageJackGold1 ( 2017-03-29 08:31:47 -0500 )edit

I have found a GitHub issue opened for this which reported similar problems:

JackGold1 gravatar imageJackGold1 ( 2017-03-29 08:31:55 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2017-03-30 02:01:55 -0500

rueynshard gravatar image

Try the omnidir:: namespace instead:, and add RECTIFY::PERSPECTIVE as one of the flags.

edit flag offensive delete link more


Thanks for your response, will give that a try and let you know how that goes.

JackGold1 gravatar imageJackGold1 ( 2017-03-31 01:11:22 -0500 )edit

I tried the omnidirectional model using the omnidir namespace, thank you for pointing me in that direction. I have been able to extract the camera and distortion matrices, as a result, I have been able to correctly undistort the image. Just one question, do you know how I can change the angle at which the undistorted image is looked at. I want to do something similar to this where the resulting image (undistorted) is looked at from an 80-degree angle. I have tried altering the cameraParameters "Knew" in the omnidir::undistortImage() function but that simply just changes the centre point and other things but it doesn't actually give me a view from an angle. Any help would be greatly appreciated.

JackGold1 gravatar imageJackGold1 ( 2017-04-20 10:25:24 -0500 )edit

Question Tools



Asked: 2017-03-29 08:31:15 -0500

Seen: 991 times

Last updated: Mar 30 '17