Reputation: 121
The camera calibration in OpenCV gives a quantitative representation of the distortion of the imaging system. For example, radial distortion can be determined by the coefficients k1, k2, k3, ... . The original position of a pixel (x,y) gets shifted to the distorted position (x_distorted, y_distorted) by the following equations [1]:
x_{distorted} = x (1+k_1 r^2 + k_2 r^4 + k_3 r^6 + ...)
y_{distorted} = y (1+k_1 r^2 + k_2 r^4 + k_3 r^6 + ...)
here, r is the distance from the center. Using OpenCV [1] I am able to get the coefficients. However, I am wondering about the units of the coefficients.
Clearly, I can not just calculate x,y and r in units of pixel. I did that, this gives my values which are 12 orders of magnitude off (!!!)
I suppose they are somewhat normalized. Where do I find the documentation on the normalization of the value?
[1] https://docs.opencv.org/4.x/dc/dbb/tutorial_py_calibration.html
I wanted to estimate the difference in x to x_distorted in units of pixel. For a very slightly distorted image (e.g. I would expect a difference of less than 5 pixel), I got a difference using the equations above of ~1*10^12.
def distortion_delta(img, center, dist):
k1, k2, p1, p2, k3 = dist
#radial distortion
distorted_x = np.zeros_like(img)
distorted_y = np.zeros_like(img)
xc, yc = center
h, w = np.shape(img)
for i in range(h):
for j in range(w):
r = np.sqrt((i-xc)**2+(j-yc)**2)
distorted_x[i,j] = (i-xc)*(1+ k1*r**2 + k2*r**4+ k3*r**6)
distorted_y[i,j] = (j-yc)*(1+ k1*r**2 + k2*r**4+ k3*r**6)
return distorted_x, distorted_y
dist = [-1.21094023e+01, 5.08189016e+02, 1.21622025e-01, -2.98076561e-03, 1.13290212e+00]
img = np.ones((50, 100))
dx, dy = distortion_delta(img, [25,50], dist)
Upvotes: 0
Views: 154