How to draw a circle in OpenCV using C++?

A circle has a center and a radius. To draw a circle using OpenCV, we have to define the center and the radius. In OpenCV we have to include <imgproc.hpp> header because 'circle()' function is defined in this header.

The basic syntax of this method is as follows −


circle(whiteMatrix, center,radius, line_Color, thickness);

The following program represents how to draw a circle in OpenCV.


using namespace cv;
using namespace std;
int main() {
   Mat whiteMatrix(200, 200, CV_8UC3, Scalar(255, 255, 255));//Declaring a white matrix
   Point center(100, 100);//Declaring the center point
   int radius = 50; //Declaring the radius
   Scalar line_Color(0, 0, 0);//Color of the circle
   int thickness = 2;//thickens of the line
   namedWindow("whiteMatrix");//Declaring a window to show the circle
   circle(whiteMatrix, center,radius, line_Color, thickness);//Using circle()function to draw the line//
   imshow("WhiteMatrix", whiteMatrix);//Showing the circle//
   waitKey(0);//Waiting for Keystroke//
   return 0;


Updated on: 10-Mar-2021

6K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started