1

This question relates to the numerical method used in undistortPoints in openCV and was asked before here:

I have an additional question. One of the answers states that undistortPoints in opencv uses the method of false position. However that is not obvious to me.

According to wikipedia, the double false position method needs two guesses. The code doesn't show 2 guesses being taken but rather only one guess is used.

I have also struggled to find anything written on false position methods with more than one variable.

Any references to help me clarify how the method used is infact a false position method would be appreciated.

The original opencv code can be found here

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
jc211
  • 397
  • 2
  • 9

1 Answers1

0

As far as I can tell, it is the Jacobi method being applied to a set of nonlinear equations.

A summarized version of the OpenCV algorithm reimplemented in python might help the explanation (notice that it is only using distortion parameters k1-k6, p1, p2 for brevity):

def undistort(u, v):
    x = (u - cx) / fx
    y = (v - cy) / fy

    x0 = x
    y0 = y

    for _ in range(5):
      r2 = x * x + y * y
      icdist = (1 + ((k6 * r2 + k5) * r2 + k4) * r2) / (1 + ((k3 * r2 + k2) * r2 + k1) * r2)
      assert icdist > 0, f"{icdist=} <= 0"
      delta_x = 2 * p1 * x * y + p2 * (r2 + 2 * x * x)
      delta_y = p1 * (r2 + 2 * y * y) + 2 * p2 * x * y
      x = (x0 - delta_x) * icdist
      y = (y0 - delta_y) * icdist

    return x, y

Do not get confused as to what x0 and y0 are. They are not working as guesses for the Jacobi method, they are just constants (u - cx) / fx and (v - cy) / fy, they do not depend on x nor y. Having said that the expression x = (x0 - delta_x) * icdist (and the equivalent for y) is just what you get once you solve symbolically the calibration equations for x, and thus that gets used for the Jacobi iterations.

As to why this works in a nonlinear set of equations, check this answer. Basically, the method usually works on "nice" non-linear functions.

Mateo de Mayo
  • 819
  • 9
  • 10