如何使用 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;
}

輸出

更新於: 10-03-2021

711 瀏覽量

開啟您的 職業生涯

完成課程以獲得認證

開始行動
廣告