1. 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 联通线型)。
2. 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联通型)
1 #include<iostream> 2 #include<opencv2/opencv.hpp> 3 using namespace cv; 4 using namespace std; 5 6 #define WINDOW_NAME1 "绘制图1" 7 #define WINDOW_NAME2 "绘制图2" 8 #define WINDOW_WIDTH 600 //定义窗口大小 9 string image = "C:\Users\asus\Pictures\Saved Pictures\123.jpg"; 10
11 void DrawEllipse(Mat img, double angle); 12 void DrawFi1ledCirc1e(Mat img, Point center); 13 int main() 14 { 15 Mat atomImage = Mat::zeros(WINDOW_WIDTH, WINDOW_WIDTH, CV_8UC3); 16 Mat rookImage = Mat::zeros(WINDOW_WIDTH, WINDOW_WIDTH, CV_8UC3); 17 //绘制椭圆 18 DrawEllipse(atomImage, 90); 19 DrawEllipse(atomImage, 0); 20 DrawEllipse(atomImage, 45); 21 DrawEllipse(atomImage, -45); 22 23 //绘制圆心 24 DrawFi1ledCirc1e(atomImage, Point(WINDOW_WIDTH / 2,WINDOW_WIDTH / 2)); 25 26 imshow(WINDOW_NAME1, atomImage); 27 waitKey(0); 28 return 0; 29 } 30 void DrawEllipse(Mat img, double angle) { 31 int thickness = 2; 32 int lineType = 8; 33 ellipse(img, Point(WINDOW_WIDTH / 2, WINDOW_WIDTH / 2), 34 Size(WINDOW_WIDTH / 4, WINDOW_WIDTH / 16), angle, 0, 360, Scalar(255, 129, 0), 35 thickness, lineType); 36 } 37 void DrawFi1ledCirc1e(Mat img, Point center) { 38 int thickness = -1; 39 int lineType = 8; 40 circle(img, center, WINDOW_WIDTH / 32, Scalar(0, 0, 255), thickness, lineType); 41 }