Ask Your Question

cv2.linearPolar() TypeError

asked 2017-07-12 10:40:43 -0600

anandvd gravatar image

updated 2017-07-12 10:51:28 -0600

I am trying to convert concentric circles into straight lines using linear polar:

circleArr = np.ndarray((512,512), dtype = np.float32)
for i in range(10,600,10):, (256,256), i-10, np.random.randint(60,500), thickness = 4)

lp = np.ndarray((512,512), dtype=np.float32)
img1 = cv2.linearPolar(circleArr, lp, (256,256), 100, cv2.INTER_LINEAR+cv2.WARP_FILL_OUTLIERS)

I get the following error referring to the last line:

TypeError: a float is required

I am confused because both the input and output array in the linearPolar() function are float type

Opencv3 and python 3.5.1

edit retag flag offensive close merge delete


I tried making it float, but still getting the same error

anandvd gravatar imageanandvd ( 2017-07-12 10:56:46 -0600 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2017-07-12 11:01:49 -0600

berak gravatar image

updated 2017-07-12 11:03:04 -0600

if you take a look at the builtin help():

>>> help(cv2.linearPolar)
Help on built-in function linearPolar:

    linearPolar(src, center, maxRadius, flags[, dst]) -> dst

you'll see, that you don't have to supply the result image (so the order of the following args is one-off).

it should be simply:

img1 = cv2.linearPolar(circleArr, (256,256), 100, cv2.INTER_LINEAR+cv2.WARP_FILL_OUTLIERS)
edit flag offensive delete link more


It works! Thanks! But in the documentation it mentions the destination as a parameter as well

anandvd gravatar imageanandvd ( 2017-07-12 11:05:25 -0600 )edit

yes, in c++. python differs a bit, so it''s always a good idea to cross-check with help() !

berak gravatar imageberak ( 2017-07-12 11:09:09 -0600 )edit

Question Tools

1 follower


Asked: 2017-07-12 10:40:43 -0600

Seen: 2,016 times

Last updated: Jul 12 '17