本文介绍了在失真的图像上使用失真系数使失真不失真的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出由径向和切向畸变定义的针孔模型的畸变系数 D = k1,k2,p1,p2,k3 .如何通过这些系数使图像失真?我知道 cv2.undistort()函数.谁能解释我如何实现不失真功能来执行迭代最小化?

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. 变形完全是径向的(切向系数p1,p2 = 0).问题归结为求解奇数级的多项式方程,并且您需要最小的正和实数解.任何方程式求解器算法都可以使用,伴随方法是常见的选择.特别是对于纯径向,单参数失真,您可以得到一个三次方程,可以使用卡尔达诺公式来解析求解.或者,您可以使用下面的递归.
  2. 一般情况下,失真方程是耦合的,您需要求解两个耦合的多项式方程的实际系统.您可能会提出这样的问题,即最大程度地减少给定的临时解决方案的残差之一,但是对于此特定的方程组,有一个捷径可用:解决方案是由失真函数本身引起的递归的固定点.有关说明,请参见Heikkila旧版中的公式(8).OpenCV代码大致基于此代码.
  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.

这篇关于在失真的图像上使用失真系数使失真不失真的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 00:25