Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

<Python, openCV> How I can use cv2.ellipse?

Tags:

python

opencv

OpenCV2 for python have 2 function


[Function 1]

  • Python: cv2.ellipse(img, center, axes, angle, startAngle, endAngle, color[, thickness[, lineType[, shift]]]) → None

[Function 2]

  • Python: cv2.ellipse(img, box, color[, thickness[, lineType]]) → None

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?

like image 829
user2743393 Avatar asked Sep 03 '13 14:09

user2743393


2 Answers

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.

like image 78
Arnaud P Avatar answered Oct 22 '22 00:10

Arnaud P


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

like image 7
Pari Avatar answered Oct 22 '22 00:10

Pari