1. 程式人生 > >cv2.fillPoly 和 cv2.fillConvexPoly:非凸任意形狀填充和凸填充

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

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)