畫圖首先要知道那些api是用來畫圖的
void ellipse(InputOutputArray img, Point center, Size axes, double angle, double startAngle, double endAngle,
const Scalar& color, int thickness = 1, int lineType = LINE_8, int shift = 0);
ellipse函數將橢圓畫到圖像 lmg 上, 橢圓中心爲點center,並且大小位於矩形 axes 內,橢圓旋轉角度爲 angle, 擴展的弧度從 0 度到 360 度,
圖形顏色爲 Scalar(x, y,z),線寬 (thickness)爲 1,線型(lineType)爲 8 (8 聯通線型)。
void circle(InputOutputArray img, Point center, int radius, const Scalar& color, int thickness = 1, int lineType = LINE_8, int shift = 0);
img :表示輸入的圖像
center: 圓心座標
radius: 圓的半徑
color:Scalar類型,表示圓的顏色,例如藍色爲Scalar(255,0,0)
thickness:線的寬度
lineType:線的類型,(默認爲8聯通型)
#include<opencv2/opencv.hpp>
#include<iostream>
using namespace cv;
int main(int argc, char** aargv)
{
Mat src;
src = imread("F:/4.png");
Mat dst = Mat::zeros(src.size(), src.type());//創建與原圖像一樣像素的純黑色的圖像
Scalar color = Scalar(255, 0, 0);
ellipse(dst, Point(dst.cols / 2, dst.rows / 2), Size(dst.cols / 4, dst.rows / 8), 90, 0, 360, color, 2, LINE_8);
ellipse(dst, Point(dst.cols / 2, dst.rows / 2), Size(dst.cols / 4, dst.rows / 8), 45, 0, 360, color, 2, LINE_8);
ellipse(dst, Point(dst.cols / 2, dst.rows / 2), Size(dst.cols / 4, dst.rows / 8), -45, 0, 360, color, 2, LINE_8);
ellipse(dst, Point(dst.cols / 2, dst.rows / 2), Size(dst.cols / 4, dst.rows / 8), 0, 0, 360, color, 2, LINE_8);
//背景圖,圓心,橫縱半軸的長度,圓在圖像中的角度,起始角度,終止角度,線的顏色,線寬,線的類型
Scalar color2 = Scalar(0, 0, 255);
Point center = Point(dst.cols / 2, dst.rows / 2);
circle(dst, center, 10, color2, -2);
namedWindow("圖片", CV_WINDOW_AUTOSIZE);
imshow("圖片", dst);
waitKey(0);
}
參考代碼
https://www.cnblogs.com/mld-code-life/p/11197736.html