opencv中常用的绘制集合图形的函数

在这里插入图片描述

line

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

参数:
img: 要绘制线段的图像。
pt1: 线段的起点。
pt2: 线段的终点。
color: 线段的颜色,通过一个Scalar对象定义。
thickness: 线条的宽度。
lineType: 线段的类型。可以取值8, 4, 和CV_AA, 分别代表8邻接连接线,4邻接连接线和反锯齿连接线。默认值为8邻接。为了获得更好地效果可以选用CV_AA(采用了高斯滤波)。
shift: 坐标点小数点位数

示例:

line(inputOutputimg, beginPoint, endPoint, Scalar(0, 0, 255), 1,8,0);

ellipse()

	bool ellipse(
		cv::Mat& img, // 待绘制的图像
		cv::Point center, // 椭圆中心
		cv::Size axes, // 椭圆长轴和短轴的长度
		double angle, // 长轴倾角
		double startAngle, // 弧度绘制的起始角度
		double endAngle, // 弧度绘制的
		const cv::Scalar& color, // 线条的颜色(RGB)
		int thickness = 1, // 线宽
		int lineType = 8, // 线型(4邻域或8邻域,默认8邻域)
		int shift = 0 // 偏移量
	);
	bool ellipse(
		cv::Mat& img, // 待绘制的图像
		const cv::RotatedRect& rect, // 椭圆的外切矩形
		const cv::Scalar& color, // 线条的颜色(RGB)
		int thickness = 1, // 线宽
		int lineType = 8, // 线型(4邻域或8邻域,默认8邻域)
		int shift = 0 // 偏移量
	);

这两个重载函数,有其他的命名:

void cvEllipse( CvArr* img, CvPoint center, CvSize axes, double angle,
                double start_angle, double end_angle, CvScalar color,
                int thickness=1, int line_type=8, int shift=0 );
void cvEllipseBox( CvArr* img, CvBox2D box, CvScalar color,
                   int thickness=1, int line_type=8, int shift=0 );

在这里插入图片描述

案例:
用定义

    ellipse(img, Point(WINDOW_WIDTH / 2, WINDOW_WIDTH / 2),
        Size(WINDOW_WIDTH / 4, WINDOW_WIDTH / 16), angle, 0, 360, Scalar(255, 129, 0),
        thickness, lineType);

用外切矩形

RotateRect r(Point2f(100,200),Size2f(50,100),45);
ellipes(resimg,r,Scalar(255,129,0),1,8);

retangle()

	void rectangle(
		cv::Mat& img, // 待绘制的图像
		cv::Point pt1, // 矩形的第一个顶点
		cv::Point pt2 // 矩形的对角顶点
		const cv::Scalar& color, // 线条的颜色(RGB)
		int lineType = 8, // 线型(4邻域或8邻域,默认8邻域)
		int shift = 0 // 偏移量
	);
	void rectangle(
		cv::Mat& img, // 待绘制的图像
		cv::Rect r, // 待绘制的矩形
		const cv::Scalar& color, // 线条的颜色(RGB)
		int lineType = 8, // 线型(4邻域或8邻域,默认8邻域)
		int shift = 0 // 偏移量
	);

fillpoly

	void fillPoly(
		cv::Mat& img, // 待绘制的图像
		const cv::Point** pts, // c风格的点序列的序列
		int* npts, // 'pts[i]'中点的数目
		int ncontours, // 'pts'中的序列数
		const cv::Scalar& color, // 线条的颜色(RGB)
		int lineType = 8, // 线型(4邻域或8邻域,默认8邻域)
		int shift = 0, // 偏移量
		cv::Point offset = Point() // 整体偏移量
	);

案例:


{
    Mat img(500, 500, CV_8U, Scalar(0));
 
    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};
    
    polylines(img, ppt, npt, 1, 1, Scalar(255),1,8,0);
    
    imshow("Test", img);
    waitKey();
    

参考博客:
1.【OpenCV3】几何图形(直线、矩形、圆、椭圆、多边形等)绘制
2. 官方文档

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值