OpenCV 16 多边形polygon绘制填充polylines() fillPoly() drawContours()

本文详细介绍了OpenCV中用于绘制多边形的`polylines()`、填充多边形的`fillPoly()`以及同时绘制填充多个多边形的`drawContours()`函数。`polylines()`仅用于绘制多边形边缘,而`fillPoly()`和`drawContours()`支持填充,其中`drawContours()`可以处理多个轮廓。示例代码展示了如何使用这些函数在图像上绘制和填充多边形。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

polylines()//只能绘制多边形,不能填充
void cv::polylines(
InputOutputArray img,
InputArrayOfArrays pts,
bool isClosed,
const Scalar & color,
int thickness = 1,
int lineType = LINE_8,
int shift = 0
)
img表示绘制画布,图像
pts表示多边形的点
isClosed表示是否闭合,默认闭合
color表示颜色
thickness表示线宽,必须是正数
lineType表示线渲染类型
shift表示相对位移

fillPoly() //填充多边形

drawContours() //可同时绘制填充多个多边形
需要提前构造多个点集的多边形

void drawContours(
InputOutputArray image,
InputArrayOfArrays contours,
int contourIdx,
const Scalar& color,
int thickness=1,
int lineType=8,
InputArray hierarchy=noArray(),
int maxLevel=INT_MAX, Point offset=Point() )

参数image 表示 目标图像,
参数contours 表示输入的轮廓组,每一组轮廓由点vector构成,
参数contourIdx 为画第几个轮廓,如果该参数为负值,则画全部轮廓,
参数color为轮廓的颜色,
参数thickness为轮廓的线宽,如果为负值或CV_FILLED表示填充轮廓内部,
参数 lineType 为 线型,
参数为 轮廓结构 信息,
参数为 maxLevel

如:std::vector<std::vector > contours;
contours.push_back(pts);
//drawContours(canvas, contours,-1, Scalar(255,0, 0),0); //一次性绘制多个
drawContours(canvas, contours, -1, Scalar(255, 0, 0),-1); //一次性填充绘制函数

void QuickDemo::polygon_drawing_demo(Mat 
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值