OpenCV中几个常用的绘图函数
通过一个小练习熟悉OpenCV中ellipse()函数、circle()函数,line()函数的使用。
//
#include<iostream>
#include<opencv2/opencv.hpp>
#include<opencv2/core/core.hpp>
#include<opencv2/imgproc/imgproc.hpp>
using namespace cv;
#define WINDOW_NAME1 "【绘制图像1】"
#define WINDOW_NAME2 "【绘制图像2】"
#define WINDOW_WIDTH 600 //定义窗口大小的宏
//绘制椭圆
void DrawEllipse(Mat img, double angle)
{
int thickness = 2;//用于定义线的宽度为2
int lineType = 8;//用于定义线的类型,为8联通类型
ellipse(img, Point(WINDOW_WIDTH / 2, WINDOW_WIDTH / 2), Size(WINDOW_WIDTH / 4, WINDOW_WIDTH / 16), angle, 0, 360, Scalar(100, 100,67), thickness, lineType);
//将椭圆画到img图像上,椭圆的中心点, 椭圆位于该矩形内, 椭圆的旋转角度为0到360度, 图形的颜色,线宽,线型
}
//绘制实心圆
void DrawFilledCircle(Mat img, Point center)
{
int thickness = -1;
int lineType = 8;
circle(img, center, WINDOW_WIDTH / 32, Scalar(0, 0, 255), thickness, lineType);//第三个参数为圆的半径
}
//绘制凹多边形的绘制
void DrawPolygon(Mat img);
//绘制线
void DrawLine(Mat img, Point start, Point end)
{
int thickness = 2;//用于定义线的粗细
int lineType = 8;//定义此线为8联通
line(img, start, end, Scalar(0, 0, 0), thickness, lineType);//调用OpenCV中的line函数
}
int main()
{
Mat atomImage = Mat::zeros(WINDOW_WIDTH, WINDOW_WIDTH, CV_8UC3);
DrawEllipse(atomImage, 90);
DrawEllipse(atomImage, 0);
DrawEllipse(atomImage, 45);
DrawEllipse(atomImage, -45);
DrawFilledCircle(atomImage, Point(WINDOW_WIDTH / 2, WINDOW_WIDTH / 2));//创建空白Mat图像
imshow(WINDOW_NAME1, atomImage);
//moveWindow(WINDOW_NAME1, 0, 200);
waitKey(0);
return(0);
}