Ask Your Question
1

How to draw ellipse with first python function ?

asked 2014-03-28 05:50:10 -0600

Guido gravatar image

updated 2014-08-12 06:11:24 -0600

Dear all,

I am trying to draw an ellipse with Opencv/Python, version 2.4.6.1. According to the doc, there are two functions :

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

I use the first as follow :

cv2.ellipse(img, (113, 155.6), (23.4, 15.2), 0.0, 0.0, 360.0, (255, 255, 255), -1);

but get the following error message

TypeError: ellipse() takes at most 5 arguments (8 given)

Any idea on how to solve this ?

edit retag flag offensive close merge delete

2 answers

Sort by » oldest newest most voted
1

answered 2014-08-11 17:59:31 -0600

lapis gravatar image

I found that axes (as well as center) has to be an integers tuple, not floats. Pretty hard to figure out by the error message OpenCV gives...

edit flag offensive delete link more
0

answered 2018-08-17 20:32:36 -0600

How to use float in this case my script is using float

    image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
    features = []

    # grab the dimensions and compute the center of the image
    (h, w) = image.shape[:2]
    (cX, cY) = (int(w * 0.5), int(h * 0.5))

    # divide the image into four rectangles/segments (top-left,
    # top-right, bottom-right, bottom-left)
    segments = [(0, cX, 0, cY), (cX, w, 0, cY), (cX, w, cY, h),
        (0, cX, cY, h)]

    # construct an elliptical mask representing the center of the
    # image
    (axesX, axesY) = (int(w * 0.75) / 2, int(h * 0.75) / 2)
    ellipMask = np.zeros(image.shape[:2], dtype = "uint8")
    cv2.ellipse(ellipMask, (cX, cY), (axesX, axesY), 0, 0, 360, 255, -1)
edit flag offensive delete link more

Question Tools

Stats

Asked: 2014-03-28 05:50:10 -0600

Seen: 8,574 times

Last updated: Aug 12 '14