![]() |
VOOZH | about |
OpenCV-Python is a library of Python bindings designed to solve computer vision problems. cv2.circle() method is used to draw a circle on any image. We use this image:
Example:
Output
Explanation: cv2.imread() loads the image and cv2.circle() draws a circle centered at (100, 100) with a radius of 50 pixels. The color (0, 255, 0) specifies green in BGR format and thickness=2 draws a 2-pixel wide outline.
cv2.circle(img, center, radius, color, thickness=None, lineType=None, shift=None)
Parameters:
Parameter | Description |
|---|---|
img | Image on which to draw (NumPy array). |
center | Center of the circle (x, y) as a tuple of integers. |
radius | Radius of the circle in pixels. |
color | Circle color as a BGR (Blue, Green, Red) tuple. |
thickness | Circle outline thickness. If -1, the circle is filled. |
lineType (Optional) | Circle boundary type. Default is 8-connected line. |
shift (Optional) | Number of fractional bits in center coordinates and radius. |
Returns: This function modifies the image directly. It does not return anything.
Example 1: In this example, we draw a filled red circle on the image.
Output
Explanation: cv2.imread() loads the image and cv2.circle() draws a filled red circle centered at (150, 150) with a radius of 40 pixels. The color (0, 0, 255) specifies red in BGR format and thickness = -1 fills the circle.
Example 2: In this example, we draw multiple circles of different colors and sizes on the image.
Output
Explanation: cv2.imread() loads the image and cv2.circle() draws blue, green and red circles at specified centers with different radii and thicknesses.
Example 3: In this example, we draw a large filled blue circle.
Output
Explanation: This draws a large filled blue circle at (250, 250) with radius 60. Then, a thick yellow outline (thickness=8) is drawn over the same circle to highlight it.