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)
| 91 | |
| 92 | |
| 93 | def 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 | |
| 112 | def clip_boxes(boxes, shape): |
no outgoing calls
no test coverage detected
searching dependent graphs…