画图首先要知道那些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