cv3.draw.ellipse
- cv3.draw.ellipse(img, x, y, axes_x, axes_y, angle=0, start_angle=0, end_angle=360, rel=None, color=None, t=None, line_type=None, fill=None, copy=False)[source]
Draw an ellipse on an image.
This is an experimental function. To use it, set experimental mode with cv3.opt.set_exp().
- Parameters:
img (numpy.ndarray) – Input image to draw on.
x (int or float) – X-coordinate of the ellipse center.
y (int or float) – Y-coordinate of the ellipse center.
axes_x (int or float) – Half of the size of the ellipse main axis x.
axes_y (int or float) – Half of the size of the ellipse main axis y.
angle (float, optional) – Ellipse rotation angle in degrees. Defaults to 0.
start_angle (float, optional) – Starting angle of the elliptic arc in degrees. Defaults to 0.
end_angle (float, optional) – Ending angle of the elliptic arc in degrees. Defaults to 360.
rel (bool, optional) – Whether to use relative coordinates. Defaults to None.
color – Color of the ellipse (default: opt.COLOR).
t – Thickness of the ellipse line. Use -1 or cv2.FILLED for filled ellipse (default: opt.THICKNESS).
line_type – Type of line for drawing (default: opt.LINE_TYPE).
fill (bool, optional) – Whether to fill the ellipse. If True, draws a filled ellipse regardless of thickness. If False, draws an outlined ellipse. If None, uses the thickness parameter to determine fill behavior. Defaults to None.
copy (bool) – Whether to copy the image before drawing (default: False).
- Returns:
Image with the ellipse drawn on it.
- Return type:
numpy.ndarray
Note
Relative coordinates are in the range [0, 1] where 0 is the top/left and 1 is the bottom/right of the image.
To draw a filled ellipse, you can either: - Use t=-1 or set the thickness parameter to -1 - Use fill=True
When fill=True, the ellipse is filled regardless of the thickness value. When fill=False, the ellipse is outlined with the specified thickness. When fill=None (default), the ellipse is filled if t=-1, otherwise outlined.
Example
>>> import cv3 >>> img = cv3.zeros(100, 100, 3) >>> # Draw an ellipse with outline >>> img = cv3.ellipse(img, 50, 50, 30, 20, color='red', t=2) >>> # Draw a filled ellipse using fill parameter >>> img = cv3.ellipse(img, 80, 80, 15, 10, color='blue', fill=True) >>> # Draw a filled ellipse using thickness parameter >>> img = cv3.ellipse(img, 20, 20, 10, 5, color='green', t=-1)