Updated April 18, 2023
Introduction to OpenCV circle
Whenever we are trying to solve problems related to computer vision, it is often necessary to draw different geometric shapes like circle, rectangle etc. and in order to draw a circle on a given image, we make use of a function called circle() function in OpenCV using which a circle of required radius from a given x coordinate and y coordinate at the center of required border line color and required border line thickness can be drawn on a given image and the image with the circle drawn on it is returned as the output by making use of the circle() function.
The syntax to define circle() function in OpenCV is as follows:
circle(sourceimage, (x coordinate, y coordinate), radius, color. thickness)
where sourceimage is the image on which the circle is to be drawn,
x coordinate and y coordinate represents the center coordinates of the circle to be drawn on the given image,
radius is the radius of the circle to be drawn on the given image,
color is the border line color of the circle to be drawn on the given image and
thickness is the border line thickness of the circle to be drawn on the given image.
Working of circle() function in OpenCV
- Whenever we are trying to solve problems related to computer vision, it is often necessary to draw different geometric shapes like circle, rectangle etc.
- In order to draw a circle on a given image, we make use of a function called circle() function in OpenCV.
- The circle() function takes five parameters namely sourceimage, (x coordinate, y coordinate), radius, color and thickness.
- The parameter sourceimage is the image on which the circle is to be drawn.
- The parameter x coordinate and y coordinate represents the center coordinates of the circle to be drawn on the given image.
- The parameter radius is the radius of the circle to be drawn on the given image.
- The parameter color is the border line color of the circle to be drawn on the given image.
- The parameter thickness is the border line thickness of the circle to be drawn on the given image.
- The circle() function returns an image on which the circle is drawn from the specified x coordinate and y coordinate, of specified radius, of specified border line color, and of specified border line thickness.
Examples of OpenCV circle
Here are the following examples mention below
Example #1
OpenCV program in python to demonstrate circle() function using which a circle is drawn from the specified x coordinate and y coordinate, of specified radius, of specified border line color, and of specified borderline thickness on a given image and returned as the output on the screen:
#importing the module cv2
import cv2
#reading the image from a given path on which the circle is to be drawn
imageread = cv2.imread('C:/Users/admin/Desktop/logo.png')
#using circle() function to draw a circle on the given image
imagecircle = cv2.circle(imageread, (120, 50), 20, (255, 0, 0), 2)
#displaying the image with circle drawn on it as the output on the screen
cv2.imwrite("C:/Users/admin/Desktop/logo1.png", imagecircle)
The output of the given program is shown in the snapshot below:
In the above program, we are importing the module cv2. Then we are reading the image on which a circle is to be drawn using imread() function. Then we making use of circle() function by specifying the sourceimage, x coordinate and y coordinate, radius, border line color and border line circle to draw a circle on the given image. The circle() function returns the image with the circle drawn on it as the output on the screen. The output is shown in the snapshot above.
Example #2
OpenCV program in python to demonstrate circle() function using which a circle is drawn from the specified x coordinate and y coordinate, of specified radius, of specified border line color, and of specified border line thickness on a given image and returned as the output on the screen:
#importing the module cv2
import cv2
#reading the image from a given path on which the circle is to be drawn
imageread = cv2.imread('C:/Users/admin/Desktop/plane.jpg')
#using circle() function to draw a circle on the given image
imagecircle = cv2.circle(imageread, (200, 100), 100, (0, 255, 0), 2)
#displaying the image with circle drawn on it as the output on the screen
cv2.imwrite("C:/Users/admin/Desktop/logo1.png", imagecircle)
The output of the given program is shown in the snapshot below:
In the above program, we are importing the module cv2. Then we are reading the image on which a circle is to be drawn using imread() function. Then we making use of circle() function by specifying the sourceimage, x coordinate and y coordinate, radius, border line color and border line circle to draw a circle on the given image. The circle() function returns the image with the circle drawn on it as the output on the screen. The output is shown in the snapshot above.
Example #3
OpenCV program in python to demonstrate circle() function using which a circle is drawn from the specified x coordinate and y coordinate, of specified radius, of specified border line color, and of specified border line thickness on a given image and returned as the output on the screen:
#importing the module cv2
import cv2
#reading the image from a given path on which the circle is to be drawn
imageread = cv2.imread('C:/Users/admin/Desktop/educba.jpg')
#using circle() function to draw a circle on the given image
imagecircle = cv2.circle(imageread, (150, 50), 50, (0, 0, 255), 2)
#displaying the image with circle drawn on it as the output on the screen
cv2.imwrite("C:/Users/admin/Desktop/logo1.png", imagecircle)
The output of the given program is shown in the snapshot below:
In the above program, we are importing the module cv2. Then we are reading the image on which a circle is to be drawn using imread() function. Then we making use of circle() function by specifying the sourceimage, x coordinate and y coordinate, radius, border line color and border line circle to draw a circle on the given image. The circle() function returns the image with the circle drawn on it as the output on the screen. The output is shown in the snapshot above.
Conclusion
In this article, we have learned the concept of circle() function in OpenCV through definition, syntax, and working of circle() function in OpenCV with corresponding programming examples and their outputs to demonstrate them.
Recommended Articles
We hope that this EDUCBA information on “OpenCV circle” was beneficial to you. You can view EDUCBA’s recommended articles for more information.