如何使用 C++ 在 OpenCV 中绘制椭圆?
要绘制椭圆,我们需要一个中心、主轴和次轴。也就是说,我们需要椭圆的三个参数。我们需要绘制椭圆的矩阵,并且需要声明线宽和线条颜色。
当我们想要使用 OpenCV 绘制椭圆时,我们必须声明旋转角度,并且还有两个其他参数:起始点和结束点。要调用“ellipse()”函数,我们需要包含 <imgproc.hpp> 头文件。
此方法的基本语法如下 −
语法
ellipse(whiteMatrix, center, xy,angle, starting_point, ending_point, 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
Size xy(100, 50);//Declaring the major and minor axis of the ellipse//
int angle = 50;//angle of rotation//
int starting_point = 0;//Starting point of the ellipse//
int ending_point = 360;//Ending point of the ellipse//
Scalar line_Color(0, 0, 0);//Color of the Ellipse//
int thickness = 2;//thickens of the line//
namedWindow("whiteMatrix");//Declaring a window to show the ellipse//
ellipse(whiteMatrix, center, xy,angle, starting_point, ending_point, line_Color,thickness);//Drawing the ellipse
imshow("WhiteMatrix", whiteMatrix);//Showing the ellipse
waitKey(0);//Waiting for Keystroke
return 0;
}输出

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