这一次,通过使用rectange、circle、ellipse函数,学习的OPENCV的数据结构。图形是乱画的。记录一下:
#include
#include
#include
#include "opencv2/imgproc/imgproc.hpp"
using namespace cv;
//define后面不要加;
#define WINDOW_WIDTH 300
//椭圆
void DrawEllipse(Mat img, double angle)
{
//线宽
int thickness = 2;
//线型
int lineType = 8;
//ellipse函数 引用头文件 "opencv2/imgproc/imgproc.hpp"、#include
ellipse(
img,
Point(150, 150),
Size(100, 50),
angle,
0,
360,
Scalar(255, 129, 0),
thickness,
lineType
);
}
//圆形
void DrawFilledCircle(Mat img, Point center)
{
int thickness = 2;
//线型
int lineType = 8;
//circle函数 引用头文件 "opencv2/imgproc/imgproc.hpp"、#include
circle(
img,
center,
120,
Scalar(0,0,255),
thickness,
lineType
);
}
void DrawRectangle(Mat img)
{
//线型
int lineType = 8;
//Rectangle 引用头文件 "opencv2/imgproc/imgproc.hpp"、#include
rectangle(
img,
//这里两个Point可以直接用rect表示
//复习一下Rect这是个矩阵图形的矩阵类 包含起点的坐标和宽度,长度
//经过学习,图像的坐标原点在左上角
Point(WINDOW_WIDTH / 3, WINDOW_WIDTH / 3),
Point(2 * WINDOW_WIDTH / 3, 2 * WINDOW_WIDTH / 3),
Scalar(0, 255, 255),
//线宽设置为-1时为颜色填充;
-1,
lineType
);
}
int main()
{
Mat img(300, 300, CV_8UC3, Scalar::all(255));
namedWindow("dddd", WINDOW_NORMAL);
//画椭圆和圆和矩形
DrawEllipse(img, 0);
DrawFilledCircle(img, Point(WINDOW_WIDTH / 2, WINDOW_WIDTH / 2));
DrawRectangle(img);
imshow("dddd",img);
waitKey();
destroyAllWindows();
}
#include
#include
#include
#include "opencv2/imgproc/imgproc.hpp"
using namespace cv;
//define后面不要加;
#define WINDOW_WIDTH 300
//椭圆
void DrawEllipse(Mat img, double angle)
{
//线宽
int thickness = 2;
//线型
int lineType = 8;
//ellipse函数 引用头文件 "opencv2/imgproc/imgproc.hpp"、#include
ellipse(
img,
Point(150, 150),
Size(100, 50),
angle,
0,
360,
Scalar(255, 129, 0),
thickness,
lineType
);
}
//圆形
void DrawFilledCircle(Mat img, Point center)
{
int thickness = 2;
//线型
int lineType = 8;
//circle函数 引用头文件 "opencv2/imgproc/imgproc.hpp"、#include
circle(
img,
center,
120,
Scalar(0,0,255),
thickness,
lineType
);
}
void DrawRectangle(Mat img)
{
//线型
int lineType = 8;
//Rectangle 引用头文件 "opencv2/imgproc/imgproc.hpp"、#include
rectangle(
img,
//这里两个Point可以直接用rect表示
//复习一下Rect这是个矩阵图形的矩阵类 包含起点的坐标和宽度,长度
//经过学习,图像的坐标原点在左上角
Point(WINDOW_WIDTH / 3, WINDOW_WIDTH / 3),
Point(2 * WINDOW_WIDTH / 3, 2 * WINDOW_WIDTH / 3),
Scalar(0, 255, 255),
//线宽设置为-1时为颜色填充;
-1,
lineType
);
}
int main()
{
Mat img(300, 300, CV_8UC3, Scalar::all(255));
namedWindow("dddd", WINDOW_NORMAL);
//画椭圆和圆和矩形
DrawEllipse(img, 0);
DrawFilledCircle(img, Point(WINDOW_WIDTH / 2, WINDOW_WIDTH / 2));
DrawRectangle(img);
imshow("dddd",img);
waitKey();
destroyAllWindows();
}