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

輸出

更新於: 10-Mar-2021

8K+ 瀏覽量

開啟你的 職業生涯

透過完成課程獲得認證

開始學習
廣告