MCPcopy Create free account
hub / github.com/tensorpack/tensorpack / polygons_to_mask

Function polygons_to_mask

examples/FasterRCNN/common.py:93–109  ·  view source on GitHub ↗

Convert polygons to binary masks. Args: polys: a list of nx2 float array. Each array contains many (x, y) coordinates. Returns: a binary matrix of (height, width)

(polys, height, width)

Source from the content-addressed store, hash-verified

91
92
93def polygons_to_mask(polys, height, width):
94 """
95 Convert polygons to binary masks.
96
97 Args:
98 polys: a list of nx2 float array. Each array contains many (x, y) coordinates.
99
100 Returns:
101 a binary matrix of (height, width)
102 """
103 polys = [p.flatten().tolist() for p in polys]
104 assert len(polys) > 0, "Polygons are empty!"
105
106 import pycocotools.mask as cocomask
107 rles = cocomask.frPyObjects(polys, height, width)
108 rle = cocomask.merge(rles)
109 return cocomask.decode(rle)
110
111
112def clip_boxes(boxes, shape):

Callers 2

__call__Method · 0.90
draw_annotationFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…