1 | initial version |
Finally, I used fsolve()
from scipy using equations I got from initUndistortRectify()
source code. I only get first 2 angles so one may needs to rotate the image.
``` def _find_angles(self, u, v): """ Finds 'alpha' and 'beta' Rodrigues' angles so that the output undistorted image is centered on a specific input pixel from the fisheye image.
:param u: x-coordinate of the pixel to center.
:param v: y-coordinate of the pixel to center.
:return: 'alpha' and 'beta' Euler angles
"""
tic = timeit.default_timer()
def _equations(ab, *args):
alpha, beta = ab
u, v, = args
w = self.dims[0]
h = self.dims[1]
f = [self.K[0, 0], self.K[1, 1]]
c = [self.K[0, 2], self.K[1, 2]]
P = self.K.copy()
P[0, 0] *= self.zoom
P[1, 1] *= self.zoom
R = cv2.Rodrigues(np.array([alpha, beta, 0.]))[0]
iR = np.linalg.inv(np.dot(P, R))
_x = h/2 * iR[0, 0] + w/2 * iR[0, 1] + iR[0, 2]
_y = h/2 * iR[1, 0] + w/2 * iR[1, 1] + iR[1, 2]
_w = h/2 * iR[2, 0] + w/2 * iR[2, 1] + iR[2, 2]
x = _x / _w
y = _y / _w
r = np.sqrt(x**2 + y**2)
theta = np.arctan(r)
theta_d = theta * (1 + self.D[0]*theta**2 + self.D[1]*theta**4 + self.D[2]*theta**6 + self.D[3]*theta**8)
scale = (r == 0) * 1.0 + (1 - (r == 0)) * theta_d / r
return f[0]*x*scale + c[0] - u, f[1]*y*scale + c[1] - v
alpha, beta = fsolve(_equations, (0., 0.), args=(u, v))
print(alpha, beta)
print("Computation time :", timeit.default_timer() - tic)
return alpha, beta
```
2 | No.2 Revision |
Finally, I used fsolve()
from scipy using equations I got from initUndistortRectify()
source code. I only get first 2 angles so one may needs to rotate the image.
```
```
def _find_angles(self, u, v):
"""
Finds 'alpha' and 'beta' Rodrigues' angles so that the output undistorted image is centered on a specific input
pixel from the fisheye image.
image.
:param u: x-coordinate of the pixel to center.
:param v: y-coordinate of the pixel to center.
:return: 'alpha' and 'beta' Euler angles
"""
tic = timeit.default_timer()
def _equations(ab, *args):
alpha, beta = ab
u, v, = args
w = self.dims[0]
h = self.dims[1]
f = [self.K[0, 0], self.K[1, 1]]
c = [self.K[0, 2], self.K[1, 2]]
P = self.K.copy()
P[0, 0] *= self.zoom
P[1, 1] *= self.zoom
R = cv2.Rodrigues(np.array([alpha, beta, 0.]))[0]
iR = np.linalg.inv(np.dot(P, R))
_x = h/2 * iR[0, 0] + w/2 * iR[0, 1] + iR[0, 2]
_y = h/2 * iR[1, 0] + w/2 * iR[1, 1] + iR[1, 2]
_w = h/2 * iR[2, 0] + w/2 * iR[2, 1] + iR[2, 2]
x = _x / _w
y = _y / _w
r = np.sqrt(x**2 + y**2)
theta = np.arctan(r)
theta_d = theta * (1 + self.D[0]*theta**2 + self.D[1]*theta**4 + self.D[2]*theta**6 + self.D[3]*theta**8)
scale = (r == 0) * 1.0 + (1 - (r == 0)) * theta_d / r
return f[0]*x*scale + c[0] - u, f[1]*y*scale + c[1] - v
alpha, beta = fsolve(_equations, (0., 0.), args=(u, v))
print(alpha, beta)
print("Computation time :", timeit.default_timer() - tic)
return alpha, beta
```
3 | No.3 Revision |
Finally, I used fsolve()
from scipy using equations I got from initUndistortRectify()
source code. I only get first 2 angles so one may needs need to rotate the image.
```
def _find_angles(self, u, v):
"""
Finds 'alpha' and 'beta' Rodrigues' angles so that the output undistorted image is centered on a specific input
pixel from the fisheye image.
:param u: x-coordinate of the pixel to center.
:param v: y-coordinate of the pixel to center.
:return: 'alpha' and 'beta' Euler angles
"""
tic = timeit.default_timer()
def _equations(ab, *args):
alpha, beta = ab
u, v, = args
w = self.dims[0]
h = self.dims[1]
f = [self.K[0, 0], self.K[1, 1]]
c = [self.K[0, 2], self.K[1, 2]]
P = self.K.copy()
P[0, 0] *= self.zoom
P[1, 1] *= self.zoom
R = cv2.Rodrigues(np.array([alpha, beta, 0.]))[0]
iR = np.linalg.inv(np.dot(P, R))
_x = h/2 * iR[0, 0] + w/2 * iR[0, 1] + iR[0, 2]
_y = h/2 * iR[1, 0] + w/2 * iR[1, 1] + iR[1, 2]
_w = h/2 * iR[2, 0] + w/2 * iR[2, 1] + iR[2, 2]
x = _x / _w
y = _y / _w
r = np.sqrt(x**2 + y**2)
theta = np.arctan(r)
theta_d = theta * (1 + self.D[0]*theta**2 + self.D[1]*theta**4 + self.D[2]*theta**6 + self.D[3]*theta**8)
scale = (r == 0) * 1.0 + (1 - (r == 0)) * theta_d / r
return f[0]*x*scale + c[0] - u, f[1]*y*scale + c[1] - v
alpha, beta = fsolve(_equations, (0., 0.), args=(u, v))
print(alpha, beta)
print("Computation time :", timeit.default_timer() - tic)
return alpha, beta
```
4 | No.4 Revision |
Finally, I used fsolve()
from scipy using equations I got from initUndistortRectify()
source code. I only get first 2 angles so one may need to rotate the image.
```
def _find_angles(self, u, v):
"""
Finds 'alpha' and 'beta' Rodrigues' angles so that the output undistorted image is centered on a specific input
pixel from the fisheye image.
:param u: x-coordinate of the pixel to center.
:param v: y-coordinate of the pixel to center.
:return: 'alpha' and 'beta' Euler angles
"""
tic = timeit.default_timer()
def _equations(ab, *args):
alpha, beta = ab
u, v, = args
w = self.dims[0]
h = self.dims[1]
f = [self.K[0, 0], self.K[1, 1]]
c = [self.K[0, 2], self.K[1, 2]]
P = self.K.copy()
P[0, 0] *= self.zoom
P[1, 1] *= self.zoom
R = cv2.Rodrigues(np.array([alpha, beta, 0.]))[0]
iR = np.linalg.inv(np.dot(P, R))
_x = h/2 * iR[0, 0] + w/2 * iR[0, 1] + iR[0, 2]
_y = h/2 * iR[1, 0] + w/2 * iR[1, 1] + iR[1, 2]
_w = h/2 * iR[2, 0] + w/2 * iR[2, 1] + iR[2, 2]
x = _x / _w
y = _y / _w
r = np.sqrt(x**2 + y**2)
theta = np.arctan(r)
theta_d = theta * (1 + self.D[0]*theta**2 + self.D[1]*theta**4 + self.D[2]*theta**6 + self.D[3]*theta**8)
scale = (r == 0) * 1.0 + (1 - (r == 0)) * theta_d / r
return f[0]*x*scale + c[0] - u, f[1]*y*scale + c[1] - v
alpha, beta = fsolve(_equations, (0., 0.), args=(u, v))
print(alpha, beta)
print("Computation time :", timeit.default_timer() - tic)
return alpha, beta
```