In this tutorial, I will show you how to draw a circle in OpenCV.

OpenCV comes with lots of built-in functions that make our life easier especially when we are working on image processing

And there is a function called circle in OpenCV which is used to draw a circle.

This function takes following parameters:

1. Image: Takes an image object
2. Center: Center point coordinates
3. Radius: Radius of the circle
4. Color: Takes color in BGR format
5. Thickness: By default set to 1 (optional)
6. Line Type: By default set to 8-connected.It can also be LINE_AA or 4-connected (Optional)
7. Shift: Shifts fractional bits in the point coordinates of center and radius (Optional)

Especially when we are creating closed shapes. Thickness plays an important role. Here if the negative thickness is passed in this function or any other function which creates a closed shape(rectangle, polygon, etc). Then it creates a filled shape (filled with color).

Negative Thickness

filled circle

Filled Circle

Positive Thickness

hollow circle

Outlined Circle

Anti Aliased Circle

Anti aliased Circle Border

Line Type Set to LINE_AA

Program

#import cv2 module
import cv2 as cv

img = cv.imread("nature.jpg")
height,width= img.shape[0:2]

#Hollow Circle
img = cv.circle(img,(width/2,height/2),100,(255,145,88),10)


#Filled Circle
#img = cv.circle(img,(width/2,height/2),100,(255,145,88),-1)

#AntiAliased Curve
#img = cv.circle(img,(width/2,height/2),250,(255,145,88),10,cv.LINE_AA)

cv.imshow('Circle',img)
cv.waitKey(0)
cv.destroyAllWindows()

Thanks for reading 🙂 🙂

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments