I have the cameraMatrix
and the distCoeff
needed to undistort an image or a vector of points. Now I\'d like to distort them back.
Is it poss
There are some points which I found when tried to redistort points using tips from this topic:
xCorrected = x * (1. + k1 * r2 + k2 * r2 * r2 + k3 * r2 * r2 * r2); // Multiply r2 after k3 one more time in yCorrected too
// To relative coordinates <- this is the step you are missing
This is wrong, as the code in this question already useы relative coordinates! It is a trick in OpenCV undistortPoints
functions. It has a new intrinsic matrix as the 6th argument. If it is None, than the function returns points in relative coordinates. And this is why the original code in question has this step:
//Step 2 : ideal coordinates => actual coordinates
xCorrected = xCorrected * fx + ux;
yCorrected = yCorrected * fy + uy;
When I started to study this question, I had the same opinion that these equations undistort points, not the opposite.
Recently I have found why. The tutorial of OpenCV and its documentation has the different names. Tutorial uses variables 'xCorrected' and 'yCorrected' for the equations. While in doc the same things have different names: 'xDistorted' and 'yDistorted'
So let's me solve the confuse: Distortion operation can be represented as equations in various distortion models. But Undistortion is only possible through numerical iteration algorithm. There is no analytical solutions to represent undistortion as equations (Because of 6th order part in radial part and nonlinearity)