Opencv绘制形状、文字

Opencv绘制形状、文字

1、 line()画直线

void line(InputOutputArray img, Point pt1, Point pt2, const Scalar&
color, int thickness = 1, int lineType = LINE_8, int shift = 0)

img: 要绘制线段的图像
pt1: 线段的起点
pt2: 线段的终点
color:线段的颜色,通过一个Scalar对象定义。
thickness: 线条的宽度
lineType:线段的类型;取时8(邻接连接线),4(反锯齿连接线),CV_AA(采用了高斯滤波)
shift: 坐标点小数点位数

line(img, cv::Point(10, 10), cv::Point(250, 250), cv::Scalar(0, 0, 255), 5, CV_AA);

2、rectangle()画矩形

void rectangle (InputOutputArray img, Point pt1, Point pt2, const
Scalar &color, int thickness=1, int lineType=LINE_8, int shift=0)

void rectangle (InputOutputArray img, Rect rec, const Scalar &color, int
thickness=1, int lineType=LINE_8, int shift=0)

img:要绘制矩形的图像
pt1:左上点
pt2:右下点
color:颜色
thickness:线条的宽度,负值时绘制一个填充矩形
shift:坐标点小数点位数
rec:(x, y, width, height)

rectangle(img, cv::Point(10, 10), cv::Point(250, 250), cv::Scalar(0, 0, 255), 1);

3、 ellipse()画椭圆

void ellipse(InputOutputArray img, Point center, Size axes, double
angle, double startAngle, double endAngle, const Scalar& color, int
thickness = 1, int lineType = LINE_8, int shift = 0);

img:要绘制椭圆的图像
center:椭圆圆心坐标
axes:轴的长度
angle:偏转的角度
start_angle:圆弧起始角的角度。.
end_angle:圆弧终结角的角度。
color:线条的颜色。
thickness:线条的宽度
line_type:线条的类型
shift:坐标点小数点位数

ellipse(img, cv::Point(400, 400), cv::Size(200,50), 90, 0, 360, cv::Scalar(255, 129, 0), 1, 1 );

4、 cvCircle()画圆

void cvCircle( CvArr* img, CvPoint center, int radius, CvScalar
color,int thickness=1, int line_type=8, int shift=0 );

img:要绘制椭圆的图像
center:圆心坐标
radius:圆的半径。
color:颜色
thickness:线条的宽度
line_type:线条的类型
shift:坐标点小数点位数

circle(img, cv::Point(200, 300), 100, cv::Scalar(225, 0, 225), 1, 1)

5、 fillPoly多边形填充
void cvFillPoly(CvArr * img, CvPoint ** pts, int * npts, int contours, CvScalar color, int line_type = 8);
img:输入图像
pts:多边形的顶点集为ppt
参数3:绘制的多边形顶点数目
参数4:要绘制的多边形数量
参数5:多边形的颜色

 Point root_points[1][4];
 root_points[0][0] = Point(215,220);
 root_points[0][1] = Point(460,225);
 root_points[0][2] = Point(466,450);
 root_points[0][3] = Point(235,465);
 const Point* ppt[1] = {root_points[0]};
 int npt[] = {4};
 fillPoly(img, ppt, npt, 1, Scalar(255255, 255));

6、 显示文字
void putText( Mat& img, const string& text, Point org, int fontFace,double fontScale, Scalar color, int thickness=1, int lineType=8 );

img:待写字的图片,我们写在img图上
text:待写入的字
org:第一个字符左下角坐标
fontFace:体类型,FONT_HERSHEY_SIMPLEX ,FONT_HERSHEY_PLAIN ,FONT_HERSHEY_DUPLEX 等等。
fontScale:字体大小
color:字体颜色
thickness:字体粗细
lineType:线型

putText(image_one, "Hello", cv::Point(50, 60), cv::FONT_HERSHEY_SIMPLEX, 2, cv::Scalar(0, 0, 255), 4, 8);

7、画多边形
void cv::polylines(InputOutputArray img, InputArrayOfArrays pts, bool isClosed, const Scalar & color,int thickness = 1, int lineType = LINE_8, int shift = 0)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值