Python OpenCV Ellipse - takes no more than 5 arguments (8 data)
I'm at a complete loss here as to why I can't draw an ellipse with OpenCV after looking at the documentation.
First I use CV 2.4.9
>>> cv2.__version__
'2.4.9'
>>>
Second, I am trying to use the following:
>>> help(cv2.ellipse)
Help on built-in function ellipse in module cv2:
ellipse(...)
ellipse(img, center, axes, angle, startAngle, endAngle, color[, thickness[,
lineType[, shift]]]) -> None or ellipse(img, box, color[, thickness[, lineType
]]) -> None
My ellipse looks like this:
cx,cy = 201,113 ax1,ax2 = 37,27 angle = -108 center = (cx,cy) axes = (ax1,ax2) cv2.ellipse(frame, center, axes, angle, 0 , 360, (255,0,0), 2)
However the startup that gives me the following
>>> cv2.ellipse(frame,center,axes,angle,0,360, (255,0,0), 2)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: ellipse() takes at most 5 arguments (8 given)
>>>
reference
Edit:
I wanted to use the following as a frame
cap = cv2.VideoCapture(fileLoc)
frame = cap.read()
Apparently it can be fixed using the following
pil_im = Image.fromarray(frame)
cv2.ellipse(frame,center,axes,angle,0,360,(255,0,0), 2)
pil_im = Image.fromarray(raw_image)
pil_im.save('C:/Development/export/foo.jpg', 'JPEG')
source to share
I had the same problem and solved it. My first line of code that I could not run was:
cv2.ellipse(ellipMask, (113.9, 155.7), (23.2, 15.2), 0.0, 0.0, 360.0, (255, 255, 255), -1);
I found that the axes (as well as the center) should be whole tuples and not float. So the line below was OK!
cv2.ellipse(ellipMask, (113, 155), (23, 15), 0.0, 0.0, 360.0, (255, 255, 255), -1);
I think you have to accept other values in order to be in the correct format.
Here is a link from the Opencv site: http://answers.opencv.org/question/30778/how-to-draw-ellipse-with-first-python-function/
source to share
Here's my iPython session, which seemed to work fine:
In [54]: cv2.__version__
Out[54]: '2.4.9'
In [55]: frame = np.ones((400,400,3))
In [56]: cx,cy = 201,113
In [57]: ax1,ax2 = 37,27
In [58]: angle = -108
In [59]: center = (cx,cy)
In [60]: axes = (ax1,ax2)
In [61]: cv2.ellipse(frame, center, axes, angle, 0 , 360, (255,0,0), 2)
In [62]: plt.imshow(frame)
Out[62]: <matplotlib.image.AxesImage at 0x1134ad8d0>
This worked - and generated the following:
So, a little weird ... Maybe there is something in the way you imported the module cv2
?
Or (rather) exactly what is the type / structure of your object frame
?
source to share