ในการวาดวงรี เราจำเป็นต้องมีศูนย์กลาง แกนหลัก และแกนรอง นั่นหมายความว่าเราต้องการพารามิเตอร์สามตัวสำหรับวงรี เราต้องการเมทริกซ์ที่เราจะวาดวงรี และเราจำเป็นต้องประกาศความหนาของเส้นและสีของเส้น
เมื่อเราต้องการวาดวงรีโดยใช้ OpenCV เราต้องพูดถึงมุมของการหมุน และมีพารามิเตอร์เพิ่มเติมสองจุดเริ่มต้นและจุดสิ้นสุด ในการเรียกใช้ฟังก์ชัน 'ellipse()' เราจำเป็นต้องรวมไฟล์ส่วนหัว
ไวยากรณ์พื้นฐานของวิธีนี้มีดังนี้ −
ไวยากรณ์
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;
} ผลลัพธ์
