Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> C++

Cách vẽ elip trong OpenCV bằng C++

Để vẽ elip, cần tâm, trục chính và trục phụ (ba tham số). Cần ma trận để vẽ, độ dày và màu đường viền. Khi vẽ elip bằng OpenCV, phải chỉ định góc xoay, điểm bắt đầu và điểm kết thúc. Hàm ellipse() yêu cầu include header <imgproc.hpp>.

Cú pháp cơ bản

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

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));
    Point center(100, 100);
    Size xy(100, 50);
    int angle = 50;
    int starting_point = 0;
    int ending_point = 360;
    Scalar line_Color(0, 0, 0);
    int thickness = 2;
    namedWindow("whiteMatrix");
    ellipse(whiteMatrix, center, xy, angle, starting_point, ending_point, line_Color, thickness);
    imshow("WhiteMatrix", whiteMatrix);
    waitKey(0);
    return 0;
}

Kết quả

Cách vẽ elip trong OpenCV bằng C++