cv3.draw.circle
- cv3.draw.circle(img, x0, y0, r, rel=None, r_mode='min', color=None, t=None, line_type=None, fill=None, copy=False)[source]
Draw a circle on an image.
- Parameters:
img (numpy.ndarray) – Input image to draw on.
x0 (int or float) – X-coordinate of the circle center.
y0 (int or float) – Y-coordinate of the circle center.
r (int or float) – Radius of the circle.
rel (bool, optional) – Whether to use relative coordinates. Defaults to None.
r_mode (str, optional) – Mode for relative radius calculation. One of ‘w’, ‘h’, ‘min’, ‘max’, ‘diag’. Only used when rel=True for the radius. Defaults to ‘min’. - ‘w’: Relative to image width - ‘h’: Relative to image height - ‘min’: Relative to minimum of width and height - ‘max’: Relative to maximum of width and height - ‘diag’: Relative to image diagonal
color – Color of the circle (default: opt.COLOR).
t – Thickness of the circle line. Use -1 or cv2.FILLED for filled circle (default: opt.THICKNESS).
line_type – Type of line for drawing (default: opt.LINE_TYPE).
fill (bool, optional) – Whether to fill the circle. If True, draws a filled circle regardless of thickness. If False, draws an outlined circle. 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 circle 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 circle, you can either: - Use t=-1 or set the thickness parameter to -1 - Use fill=True
When fill=True, the circle is filled regardless of the thickness value. When fill=False, the circle is outlined with the specified thickness. When fill=None (default), the circle is filled if t=-1, otherwise outlined.
Example
>>> import cv3 >>> img = cv3.zeros(100, 100, 3) >>> # Draw a circle with outline >>> img = cv3.circle(img, 50, 50, 30, color='red', t=2) >>> # Draw a filled circle using fill parameter >>> img = cv3.circle(img, 80, 80, 15, color='blue', fill=True) >>> # Draw a filled circle using thickness parameter >>> img = cv3.circle(img, 20, 20, 10, color='green', t=-1) >>> # Draw a circle with relative radius based on image width >>> img = cv3.circle(img, 0.5, 0.5, 0.2, rel=True, r_mode='w', color='yellow')