如何使用 C++ 在 OpenCV 中绘制一个圆?
圆有一个圆心和一个半径。要使用 OpenCV 绘制一个圆,我们必须定义圆心和半径。在 OpenCV 中,我们必须包含<imgproc.hpp> 头文件,因为 'circle()' 函数是在此头文件中定义的。
此方法的基本语法如下 −
语法
circle(whiteMatrix, center,radius, line_Color, thickness);
以下程序说明了如何在 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));//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;
}输出

广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP