OpenCV2 for python have 2 function
I want to use [Function 1]
But when I use this Code
cv2.ellipse(ResultImage, Circle, Size, Angle, 0, 360, Color, 2, cv2.CV_AA, 0)
It raise
TypeError: ellipse() takes at most 5 arguments (10 given)
Could you help me?
The fact that Python doesn't support multiple dispatch by default doesn't help here: having two functions with the same name but different parameters is not pythonic. So the question is: how does cv2
guess the version we'd like to call ? I couldn't find any explicit doc on that.
Anyhow, after experiencing the same issue with opencv 3.0.0-beta and Python 3.4.2, I finally found out that in my case one of the circle's point was a float
, and although I was running the official samples code with 8 parameters, for some reason cv2 defaulted to the 5-args function. Using int
fixed the problem, so the error message was pretty misleading.
I believe going from Python 2 to 3 may bring that kind of confusion in existing code, since integer divisions return floats in Python 3.
Make sure all the ellipse parameters are int otherwise it raises "TypeError: ellipse() takes at most 5 arguments (10 given)". Had the same problem and casting the parameters to int, fixed it.
Please note that in Python, you should round the number first and then use int(), since int function will cut the number:
x = 2.7 , int(x) will be 2 not 3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With