openCV函数使用(二)
绘制直线:
void line(Mat& img, Point pt1, Point pt2, const Scalar& color, int thickness=1, int lineType=8, int shift=0);
1:输入图像。2:起点。3:终点。4:颜色。5:粗细。
6:表示线段的类型。可以取值8,4,和CV_AA,分别代表8邻接连接线,4邻接连接线和反锯齿连接线。默认值为8。
7:表示坐标点小数点位数。
line(src, Point(1, 1), Point(250, 250), Scalar(255, 0, 0), 1, CV_AA);
绘制椭圆:
void Ellipse( Arr* img, Point center, Size axes, double angle, double start_angle, double end_angle, Scalar color, int thickness=1, int line_type=8, int shift=0 );
1:输入图像。2:圆心坐标。(Point)3:轴长度。(Size)4:偏转角度。5:圆弧起始角度。.
6:圆弧终结角度。7:线条的颜色。(Scalar)8:线条的粗细。9:线条类型。
10:圆心坐标点和数轴的精度。
ellipse(src, Point(270, 230), Size(100, 50), 60, 0, 360, Scalar(255, 0, 0), 1, 8);
绘制圆:
void circle(InputOutputArray img, Point center, int radius, const Scalar& color, int thickness = 1, int lineType = LINE_8, int shift = 0);
1:输入图像。2:圆心坐标。3:圆半径。4:线条颜色。5:线条粗细。6:线条类型。
7:圆心坐标点和数轴的精度。
circle(src, Point(270, 230), 100, Scalar(255, 0, 0), 1, CV_AA);
绘制填充多边形:
void fillPoly(Mat& img, const Point** pts, const int* npts, int ncontours, const Scalar& color, int lineType=8, int shift=0, Point offset=Point());
1:输入图像。2:指向多边形的指针数组。(const)3:多边形的顶点个数。(数组)
4:多边形的个数。5:填充颜色。6:线条粗细。7:顶点坐标的小数点位数。
Point p[1][5] = {{Point(100, 100), Point(150, 50), Point(200, 100),Point(250,200),Point(50, 200)}};
const Point* pp[] = { p[0]};
int n[] = {5};
fillPoly(src, pp, n, 1, Scalar(255, 0, 0));
绘制多边形:
void polylines(Mat& img, const Point** pts, const int* npts, int ncontours, bool isClosed, const Scalar& color, int thickness=1, int lineType=8, int shift=0);
1:输入图像。2:多边形的指针数组。(const)3:多边形的顶点个数。(数组)
4:多边形的个数。5:多边形是否闭合,1表示闭合,0表示不闭合。
6:多边形的颜色。7:线条粗细。8:线条类型。9:顶点坐标的小数点位数。
Point p[2][5] = { {Point(100, 100), Point(150, 50),Point(250,200), Point(200, 100),Point(50, 200)},{Point(350,350),Point(450,300),Point(400,200)} };
const Point* pp[] = { p[0],p[1] };
int n[] = { 5,3 };
polylines(src, pp, n, 2, 1, Scalar(255, 0, 0), 1, CV_AA);
绘制矩形:
void rectangle(InputOutputArray img, Point pt1, Point pt2, const Scalar& color, int thickness = 1, int lineType = LINE_8, int shift = 0);
1:输入图像。2:矩形左上角顶点。3:矩形右下角顶点。4:矩形颜色。
5:线条粗细。
FILLED = -1, //取负值时(如 CV_FILLED)函数绘制填充了色彩的矩形
6:线条类型。其中:LINE_4 = 4,LINE_8 = 8, LINE_AA = 16,
rectangle(src, Point(0, 0), Point(200, 200), Scalar(255, 0, 0), -1, 8);
绘制文字:
void putText(Mat& img, const string& text, Point org, int fontFace, double fontScale, Scalar color, int thickness=1, int lineType=8, bool bottomLeftOrigin=false);
1:输入图像。2:添加文字。3:文字在图像左下角的坐标。
4:字体类型。
FONT_HERSHEY_SIMPLEX, FONT_HERSHEY_PLAIN,
FONT_HERSHEY_DUPLEX,FONT_HERSHEY_COMPLEX,
FONT_HERSHEY_TRIPLEX, FONT_HERSHEY_COMPLEX_SMALL,
FONT_HERSHEY_SCRIPT_SIMPLEX, FONT_HERSHEY_SCRIPT_COMPLEX
以上所有类型都可以配合 FONT_HERSHEY_ITALIC使用,产生斜体效果。
5:字体大小。6:字体颜色。7:字体粗细。8:线条类型。
9:true, 图像数据原点在左下角. false, 图像数据原点在左上角。
putText(src, "hello Natsume", Point(370, 350), FONT_HERSHEY_SIMPLEX, 1, Scalar(255, 0, 0), 1, 8, false);