OpenCV cv2 circle method Implementation

OpenCV cv2 circle method Implementation with steps

GET FREE AMZAON AUDIOBOOKS

OpenCv is the best library for computer vision problems. It has many inbuilt functions that allow you to do so. Suppose you have an image and wants to draw a circle on it then how you can do so. In this entire tutorial, you will know how you can draw a circle on the image using the cv2 circle() method in OpenCV.

Steps to implement cv2 circle

In this section, you will know all the steps to follow for implementing the cv2 circle on an image. Please note that you should follow each step one by one for better understanding.

Step 1: Import required library

The first step is to import all the necessary package. In this entire tutorial, I am using only OpenCV packages. So let’s import it using the import statement.

import cv2

Step 2: Read or load the image

Now the second step is to read the image for drawing a circle on it. In OpenCV you can read an image using the cv2.imread() method. Execute the below lines of code to read the image.

Sample Image

bird image for cv2 circle implementation
bird image for cv2 circle implementation

Step 3: Draw the circle

The method accepts various parameters of manipulating the input image. Below is the syntax of the method.

cv2.circle(image, center_coordinates, radius, color, thickness)

The explanation of the parameters is the following.

image: Input Image

center_coordinates: The x and y-axis value for the circle.

radius: The radius of the circle.

color: Color of the circle.

thickness : The thickness of the border of the circle.

Now, let’s draw a circle on the image.

Simple Circle Drawing

For a simple circle drawing on the image, you have to execute the below lines of code. It is without thickness in the border.

import cv2
img = cv2.imread("bird.jpg")
center_coordinates = (100,100)
radius =50
color = (255, 255, 255)
image = cv2.circle(img,center_coordinates,radius,color)
cv2.imshow("Bird Image with circle",image)
cv2.waitKey(0)

Output

Drawing circle on the image using cv2 circle
Drawing circle on the image using cv2 circle

Drawing circle with a thickness

You can also add thickness to the border of the image. You have to just pass the thickness parameter inside the cv2.circle()as a parameter. Just execute the full lines of code given below.

import cv2
img = cv2.imread("bird.jpg")
center_coordinates = (100,100)
radius =50
color = (255, 255, 255)
thickness = 10
image = cv2.circle(img,center_coordinates,radius,color,thickness)
cv2.imshow("Bird Image with circle",image)
cv2.waitKey(0)

Output

Drawing circle on the image with thickness using cv2 circle
Drawing circle on the image with thickness using cv2 circle

Conclusion

These are steps for implementing cv2 circle using OpenCV in python. You can draw circles on your face or object detection projects. I hope you have liked this tutorial. If you have any queries then you can contact us for more help.\

Source:

OpenCV documentation 

Join our list

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.

Thank you for signup. A Confirmation Email has been sent to your Email Address.

Something went wrong.

 
Thank you For sharing.We appreciate your support. Don't Forget to LIKE and FOLLOW our SITE to keep UPDATED with Data Science Learner