Computer >> Máy Tính >  >> Lập trình >> C ++

Làm thế nào để vẽ một Ellipse trong OpenCV bằng C ++?

Để vẽ một hình elip, chúng ta cần một tâm, trục chính và trục nhỏ. Điều đó có nghĩa là chúng ta cần ba tham số cho hình elip. Chúng ta cần một ma trận để vẽ hình elip và chúng ta cần khai báo độ dày của đường kẻ và màu sắc của đường kẻ.

Khi chúng ta muốn vẽ một hình elip bằng OpenCV, chúng ta phải đề cập đến góc quay, và có hai tham số bổ sung là điểm bắt đầu và điểm kết thúc. Để gọi hàm 'ellipse ()', chúng ta cần bao gồm tệp tiêu đề .

Cú pháp cơ bản của phương thức này như sau -

Cú pháp

ellipse(whiteMatrix, center, xy,angle, starting_point, ending_point, line_Color,thickness);

Chương trình sau đây cho biết cách vẽ một hình elip trong OpenCV.

Ví dụ

#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;
}

Đầu ra

Làm thế nào để vẽ một Ellipse trong OpenCV bằng C ++?