Opencv: distort back

后端 未结 7 687
清歌不尽
清歌不尽 2021-02-02 02:53

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

7条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-02 02:58

    There are some points which I found when tried to redistort points using tips from this topic:

    1. Code in the question is almost right, but has a bug. It uses r^4 after k3 instead of r^6. I rewrote code and successfully run after this simple correction.

    xCorrected = x * (1. + k1 * r2 + k2 * r2 * r2 + k3 * r2 * r2 * r2); // Multiply r2 after k3 one more time in yCorrected too

    1. Joan Charman said the right things and equations allow to distort point back (Not undistort, as mentioned in comments under his answer). However, some words are incorrect:

    // 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;
    
    1. Also, I have to say about confusion in the Internet material.

    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)

提交回复
热议问题