cv2.fillPoly 和 cv2.fillConvexPoly:非凸任意形状填充和凸填充

本文详细介绍了OpenCV中用于填充多边形的两个函数:cv2.fillPoly与cv2.fillConvexPoly。cv2.fillPoly能够填充复杂的多边形区域,包括有洞或多边形自相交的情况;而cv2.fillConvexPoly主要用于填充凸多边形,其运行速度更快。文中还提供了具体的使用示例。

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

cv2.fillConvexPoly:
官方文档:The function fillConvexPoly draws a filled convex polygon. This function is much faster than the function fillPoly . It can fill not only convex polygons but any monotonic polygon without self-intersections, that is, a polygon whose contour intersects every horizontal line (scan line) twice at the most (though, its top-most and/or the bottom edge could be horizontal).
使用方法:

import cv2
import numpy

a = numpy.zeros((10,10))
triangle = numpy.array([ [1,3], [4,8], [1,9] ], numpy.int32)#[1,3],[4,8],[1,9]为要填充的轮廓坐标
cv2.fillConvexPoly(a, triangle, 1)

cv2.fillPoly:
官方文档:The function fillPoly fills an area bounded by several polygonal contours. The function can fill complex areas, for example, areas with holes, contours with self-intersections (some of their parts), and so forth.
使用方法:

cv2.fillPoly(a, [triangle], 1)

如果有多个形状:

cv2.fillPoly(a, [triangle, square, hexagon], 1)
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值