Using distortion co-efficients on a distorted image to un-distort

不想你离开。 提交于 2021-01-29 05:44:36

问题


Given the distortion co-efficients D = k1,k2,p1,p2,k3 of a pinhole model which is defined by radial and tangential distortion. How to undistort an image with these co-efficients? I know about the cv2.undistort() function. Can anyone explain me how to implement the undistortion function to perform iterative minimization?

    # TODO: Iterative minimization required
    r2 = x_ * x_ + y_ * y_
    # Remove tangential distortion
    x_tangential = x_ - (2 * distort_coeffs[2] * x_ * y_ + distort_coeffs[3] * (r2 + 2 * x_ * x_))
    y_tangential = y_ - (distort_coeffs[2] * (r2 + 2 * y_ * y_) + 2 * distort_coeffs[3] * x_ * y_)
    # Remove radial distortion
    x = x_tangential / (1 + distort_coeffs[0] * r2 + distort_coeffs[1] * r2 * r2 + distort_coeffs[4] * r2 * r2 * r2)
    y = y_tangential / (1 + distort_coeffs[0] * r2 + distort_coeffs[1] * r2 * r2 + distort_coeffs[4] * r2 * r2 * r2)

    cam_coords_undistorted = torch.cat([x, y, ones], 1)

回答1:


There are two cases:

  1. The distortion is purely radial (tangential coefficients p1, p2 = 0). The problem boils down to solving a polynomial equation of odd degree, and you want the smallest solution that is positive and real. Any equation solver algorithm will do, the adjoint method being a common choice. For pure radial, single-parameter distortion, in particular, you get a third-degree equation that can be solved analytically using Cardano's formula. Or you can use the recursion below.
  2. General case, the distortion equations are coupled, and you need to solve an actual system of two coupled polynomial equations. You could pose the problem as one of minimizing the residual for a given tentative solution, but for this particular system of equations there is a shortcut available: the solution is a fixed point of the recursion induced by the distortion function itself. See equation (8) in Heikkila's old paper for an explanation. The OpenCV code is loosely based on it.


来源:https://stackoverflow.com/questions/54595566/using-distortion-co-efficients-on-a-distorted-image-to-un-distort

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!