Transform Polar to Cartesian co-ordinates?
I've written the following python code that 'unravels' an iris from a pupil (i.e. given a central point, it sweeps round 360 degrees and prints out the iris as a long strip (i.e. a rectangle).
The problem is, this code is very slow in Python; is there a good way to do this using OpenCV?
def unravel(img, pupil):
height, width, depth = img.shape
max_radius = 180
min_radius = int(pupil[2])
out = np.zeros((max_radius-min_radius,720,3), np.uint8)
for phi in range(0,720):
for r in range(min_radius, max_radius):
target = cmath.rect(r,math.radians(phi/2))
out[(r-min_radius,phi)] = img[(pupil[1] + target.real, pupil[0]+target.imag)]
return out
Input:
(Cropped) output:
add a comment