Ask Your Question

Difference between undistort and initUndistortRectifyMap+remap?

asked 2014-09-24 06:38:28 -0500

Hello! I am currently trying to speed up the my image acquisition by replacing a call to cv::undistort for every image with a single use of initUndistortRectifyMap and then only a cv::remap for every image.

Currently, my test callback looks like this:

        cv::Mat undistorted;

        Mat map1,map2;
        Mat newCamMatrix;
        cv::initUndistortRectifyMap(camm,dist,Mat(),newCamMatrix, cv::Size(img.cols,img.rows), CV_32FC1, map1,map2);

        cout << "old matrix" << endl << camm << endl;
        cout << "new matrix" << endl << newCamMatrix << endl;

        Mat undis2;

        cv::imwrite("/opt/tmp/undis1.png", undistorted);
        cv::imwrite("/opt/tmp/undis2.png", undis2);

camm is here my camera matrix and dist my distortion vector. Both undistorted images look similar, but the second image (the remapped one) is shifted about 20pixels in vertical direction and shows a different part of the original image.

The undistort code can be found e.g. here:

Does anyone know why the undistortion is done in stripes? And more important: How can I use initUndistortRectifyMap to get the same result as with undistort and which is the correct result?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2015-05-20 10:19:34 -0500

MarcelDebout gravatar image

Hey FooBar!

I figured out, that changing the line:

initUndistortRectifyMap(camm, dist, Mat(), newCamMatrix, Size(img.cols,img.rows),CV_32FC1,map1,map2);


initUndistortRectifyMap(camm, dist, Mat(), camm, Size(img.cols,img.rows), CV_32FC1, map1, map2);

should solve your problem.

The funciton


offers you to apply a transformation. The translation is given by the c_x and c_y values of your camera matrix.

edit flag offensive delete link more


Worked perfectly for me, thanks!

cvHobbyIst gravatar imagecvHobbyIst ( 2015-07-24 08:05:28 -0500 )edit

That's really correct

neurobot gravatar imageneurobot ( 2016-11-10 22:19:37 -0500 )edit
Login/Signup to Answer

Question Tools


Asked: 2014-09-24 06:38:28 -0500

Seen: 4,335 times

Last updated: Sep 24 '14