// opencv 绘图函数
// CV_EXPORTS_W void line(CV_IN_OUT Mat& img, Point pt1, Point pt2, const Scalar& color,
// int thickness=1, int lineType=8, int shift=0);
//参数解释
//.Mat& img: 输入输出图像
//.Point pt1和pt2: 二维Point类的点坐标,由Point指定
//.Scalar& color: 直线颜色
//. int thickness = 1: 直线宽度,有默认值1
//. int lineType = 8: 直线类型,默认值为8
//CV_EXPORTS_W void ellipse(CV_IN_OUT Mat& img, Point center, Size axes,
// double angle, double startAngle, double endAngle,
// const Scalar& color, int thickness = 1,
// int lineType = 8, int shift = 0);
//参数解释
//.Mat& img: 输入输出图像
//.Point center : 由Point类指定的椭圆中心坐标
//.Size axes : 由Size类指定的椭圆所在区域矩形
//. double angle : 椭圆长轴偏离角度
//. double startAngle : 绘制椭圆起始角度
//. double endAngle : 绘制椭圆终点角度。如果设置startAngle为0,
//设置endAngle为360则表示整个椭圆
//. const Scalar& color : 椭圆颜色
//. int thickness = 1 : 椭圆边的线宽
//. int lineType = : 椭圆变线的类型
//
//CV_EXPORTS_W void rectangle(CV_IN_OUT Mat& img, Point pt1, Point pt2,
// const Scalar& color, int thickness = 1,
// int lineType = 8, int shift = 0);
//
! draws the rectangle outline or a solid rectangle covering rec in the image
//CV_EXPORTS void rectangle(CV_IN_OUT Mat& img, Rect rec,
// const Scalar& color, int thickness = 1,
// int lineType = 8, int shift = 0);
//可以看出其有两种参数传入方式。一类是用Point指定点,另一类是用Rect函数指定边长。
//.针对第一类指定方式,Point类指定的两个点分别为矩形的左上角点坐标和矩形左下角点坐标
//.Rect指定边长,查看其定义有如下语句
//说明Rect是int类型的数据结构,与Rect_等价。
//
//CV_EXPORTS_W void circle(CV_IN_OUT Mat& img, Point center, int radius,
// const Scalar& color, int thickness = 1,
// int lineType = 8, int shift = 0);
//参数解释
//.Mat& img: 输入输出图像
//.Point center : Point指定的一个二维点作为圆心
//. int radius : 圆的半径
//. const Scalar& color : Scalar指定的绘制圆的颜色
//. int thickness = 1 : 圆边的线宽
//. int lineType = 8 : 圆边线的类型
//
//填充多边形。其定义有两种形式
//
//CV_EXPORTS void fillPoly(Mat& img, const Point** pts,
// const int* npts, int ncontours,
// const Scalar& color, int lineType = 8, int shift = 0,
// Point offset = Point());
//
//CV_EXPORTS_W void fillPoly(InputOutputArray img, InputArrayOfArrays pts,
// const Scalar& color, int lineType = 8, int shift = 0,
// Point offset = Point());
//.第一种形式定义,有Point** pts,是一个二阶指针,用来指定多边形顶点。
//多边形顶点不是某个特定点,而是多个点,所以用Point类定义的数组来表示顶点坐标,
//
//
#include
#include
#include
using namespace std;
using namespace cv;
void M1(Mat img, double a1);
void M2(Mat img, Point c1);
void M3(Mat img, Point s1, Point s2);
void M4(Mat img);
const int w = 400;
int main()
{
char awindow[] = "图 1";
char rwindow[] = "图 2";
// 创建空的图像
//Mat aimage = Mat::zeros(w, w, CV_8UC3);
Mat aimage = imread("F:/2.jpg");
Mat rimage = Mat::zeros(w, w, CV_8UC3);
M1(aimage, 90);
M1(aimage, 0);
M1(aimage, 45);
M1(aimage, -45);
M2(aimage, Point(w / 2.0, w / 2.0));
namedWindow(awindow, WINDOW_AUTOSIZE);
imshow(awindow, aimage);
M4(rimage);
// 创建一个矩形,
rectangle(rimage, Point(0, 7 * w / 8.0), Point(w, w), Scalar(0, 255, 255), -1, 8);
M3(rimage, Point(0, 15 * w / 16), Point(w, 15 * w / 16));
M3(rimage, Point(w/4, 7 * w / 8), Point(w/4, w));
M3(rimage, Point(w / 2, 7 * w / 8), Point(w / 2, w));
M3(rimage, Point(3 * w / 4, 7 * w / 8), Point(3 * w / 4, w));
namedWindow(rwindow, WINDOW_AUTOSIZE);
imshow(rwindow, rimage);
waitKey(0);
return 0;
}
void M1(Mat img, double a1)
{
int thickness = 2;
int linetype = 8;
ellipse(img, Point(w / 2.0, w / 2.0), Size(w / 4.0, w / 16.0),
a1, 0, 360, Scalar(0, 255, 255), thickness, linetype);
}
void M2(Mat img, Point c1)
{
int thickness = -1;
int linetype = 8;
circle(img, c1, w / 32.0, Scalar(0, 0, 255), thickness, linetype);
}
void M3(Mat img, Point s1, Point s2)
{
int thickness = 2;
int linetype = 8;
line(img, s1, s2, Scalar(0, 0, 0), thickness, linetype);
}
void M4(Mat img)
{
int lineType = 8;
Point rpoint[1][20];
rpoint[0][0] = Point(w / 4.0, 7 * w / 8.0);
rpoint[0][1] = Point(3 * w / 4.0, 7 * w / 8.0);
rpoint[0][2] = Point(3 * w / 4.0, 13 * w / 16.0);
rpoint[0][3] = Point(11 * w / 16.0, 13 * w / 16.0);
rpoint[0][4] = Point(19 * w / 32.0, 3 * w / 8.0);
rpoint[0][5] = Point(3 * w / 4.0, 3 * w / 8.0);
rpoint[0][6] = Point(3 * w / 4.0, w / 8.0);
rpoint[0][7] = Point(26 * w / 40.0, w / 8.0);
rpoint[0][8] = Point(26 * w / 40.0, w / 4.0);
rpoint[0][9] = Point(22 * w / 40.0, w / 4.0);
rpoint[0][10] = Point(22 * w / 40.0, w / 8.0);
rpoint[0][11] = Point(18 * w / 40.0, w / 8.0);
rpoint[0][12] = Point(18 * w / 40.0, w / 4.0);
rpoint[0][13] = Point(14 * w / 40.0, w / 4.0);
rpoint[0][14] = Point(14 * w / 40.0, w / 8.0);
rpoint[0][15] = Point(w / 4.0, w / 8.0);
rpoint[0][16] = Point(w / 4.0, 3 * w / 8.0);
rpoint[0][17] = Point(13 * w / 32.0, 3 * w / 8.0);
rpoint[0][18] = Point(5 * w / 16.0, 13 * w / 16.0);
rpoint[0][19] = Point(w / 4.0, 13 * w / 16.0);
const Point* pp[1] = { rpoint[0] };
int npt[] = { 20 };
fillPoly(img, pp, npt, 1, Scalar(255, 255, 255), lineType);
}
参考大神网页:https://blog.csdn.net/keith_bb/article/details/53313202