如何使用 C++ 在 OpenCV 中绘制一个圆?
opencvc++server side programmingprogramming更新于 2025/5/14 17:22:17
圆有一个圆心和一个半径。要使用 OpenCV 绘制圆,我们必须定义圆心和半径。在 OpenCV 中,我们必须包含 <imgproc.hpp> 标头,因为 'circle()' 函数在此标头中定义。
此方法的基本语法如下 −
语法
circle(whiteMatrix, center,radius, line_Color, thicken);
以下程序表示如何在 OpenCV 中绘制圆。
示例
#include<iostream> #include<opencv2/highgui/highgui.hpp> #include<opencv2/imgproc/imgproc.hpp> using namespace cv; using namespace std; int main() { Mat whiteMatrix(200, 200, CV_8UC3, Scalar(255, 255, 255));//声明白色矩阵 Point center(100, 100);//声明中心点 int radius = 50; //声明半径 Scalar line_Color(0, 0, 0);//圆的颜色 int thick = 2;//线的粗细 namedWindow("whiteMatrix");//声明一个窗口来显示圆圈 circle(whiteMatrix, center,radius, line_Color, thick);//使用circle()函数绘制线条// imshow("WhiteMatrix", whiteMatrix);//显示圆圈// waitKey(0);//等待按键// return 0; }