C++联合OpenCV学习——图形绘制

OpenCV基本图形的绘制

主要分为以下五点

  1. 绘制直线Line函数
  2. 绘制椭圆Ellipse函数
  3. 绘制矩形Rectangle函数
  4. 绘制圆形Circle函数
  5. 绘制多边形FillPoly函数
    自定义函数
//#define WINDOW_WIDTH 600
void DrawLine(Mat Image, Point start,Point end) {
    int thickness = 2;
    int lineType = 8;

    line(Image,start,end,Scalar(0,0,255),thickness,lineType);
    /*
    用于在图形上画一条从点start到点end的直线段,线的颜色为Scalar(0,0,255)红色,
    线的粗细thickness为2,且此线为8联通(lineType = 8)
    */
}
void DrawEllopse(Mat Image,double angle){
	int thickness = 2;
	int lineType = 8;
	
	ellipse(Image,Point(600/2, 600 / 2),Size(600/4, 600/16),angle,0,360,Scalar(255,129,0),thickness ,lineType );
	/*
    Point(600/2,600/2)为椭圆中心点,并且大小为位于矩形Size(600/4,600/16)。椭圆角度为angle,扩展的弧度是从0到360度。
    图形颜色为Scalar(255,129,0),线框thickness为2,线型lineType为8(8连通线型)
    */
}
void DrawFilledCircle(Mat Image,Point center) {
    int thickness = -1;
    int lineType = 8;

    circle(Image,center, 600/32,Scalar(0,0,255),thickness,lineType);
    /*
    center为圆心,圆的半径为600/32,圆的颜色为Scalar(0,0,255),
    按RGB的格式为红色,线粗定义为thickness = -1,因此绘制的圆是实心的
    */
}
void DrawPolygon(Mat Image) {
    int lineType = 8;
    //创建一些点
    Point rookPoints[1][6];
    rookPoints[0][0] = Point(600 / 4, 7 * 600 / 8);
    rookPoints[0][1] = Point(800, 7 * 800 / 8);
    rookPoints[0][2] = Point(800 / 4, 1200);
    rookPoints[0][3] = Point(1000 / 4, 2 * 800 / 4);
    rookPoints[0][4] = Point(1000, 1100);
    rookPoints[0][5] = Point(650, 4 * 600 / 8);

    const Point* ppt[1] = { rookPoints[0] };
    int npt[] = { 6 };
    fillPoly(Image,ppt,npt,1,Scalar(255,0,255),lineType);
    /*
    ppt为多边形的顶点集,要绘制的多边形顶点数目为npt,要绘制的多边形数量仅为1,多边形的颜色定义为紫色Scalar(255,0,255)
    */
}


void DrawEllipse(Mat Image,double angle) {

    ellipse(Image, Point(600 / 2, 600 / 2), Size(600 / 4, 600 / 16), angle, 0, 360, Scalar(255, 129, 0), 1, 8);
    /*
    Point(600/2,600/2)为椭圆中心点,并且大小为位于矩形Size(600/4,600/16)。椭圆角度为angle,扩展的弧度是从0到360度。
    图形颜色为Scalar(255,129,0),线框thickness为2,线型lineType为8(8连通线型)
    */
}

你可能感兴趣的:(c++,计算机视觉,opencv)