Skip to content

Commit

Permalink
[Feature] Support visualization for Panoptic Segmentation (open-mmlab…
Browse files Browse the repository at this point in the history
…#7041)

* First commit of v2

* split the functions

* Support to show panoptic result

* temp

* Support to show gt

* support show gt

* fix lint

* Support to browse datasets

* Fix unit tests

* Fix findContours

* fix comments

* Fix pre-commit

* fix lint

* Add the type of an argument
  • Loading branch information
AronLin authored and chhluo committed Feb 21, 2022
1 parent 325cc47 commit 316da26
Show file tree
Hide file tree
Showing 11 changed files with 536 additions and 132 deletions.
2 changes: 1 addition & 1 deletion mmdet/apis/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,5 +238,5 @@ def show_result_pyplot(model,
wait_time=wait_time,
win_name=title,
bbox_color=palette,
text_color=palette,
text_color=(200, 200, 200),
mask_color=palette)
30 changes: 30 additions & 0 deletions mmdet/core/mask/structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -1070,3 +1070,33 @@ def polygon_to_bitmap(polygons, height, width):
rle = maskUtils.merge(rles)
bitmap_mask = maskUtils.decode(rle).astype(np.bool)
return bitmap_mask


def bitmap_to_polygon(bitmap):
"""Convert masks from the form of bitmaps to polygons.
Args:
bitmap (ndarray): masks in bitmap representation.
Return:
list[ndarray]: the converted mask in polygon representation.
bool: whether the mask has holes.
"""
bitmap = np.ascontiguousarray(bitmap).astype(np.uint8)
# cv2.RETR_CCOMP: retrieves all of the contours and organizes them
# into a two-level hierarchy. At the top level, there are external
# boundaries of the components. At the second level, there are
# boundaries of the holes. If there is another contour inside a hole
# of a connected component, it is still put at the top level.
# cv2.CHAIN_APPROX_NONE: stores absolutely all the contour points.
outs = cv2.findContours(bitmap, cv2.RETR_CCOMP, cv2.CHAIN_APPROX_NONE)
contours = outs[-2]
hierarchy = outs[-1]
if hierarchy is None:
return [], False
# hierarchy[i]: 4 elements, for the indexes of next, previous,
# parent, or nested contours. If there is no corresponding contour,
# it will be -1.
with_hole = (hierarchy.reshape(-1, 4)[:, 3] >= 0).any()
contours = [c.reshape(-1, 2) for c in contours]
return contours, with_hole
Loading

0 comments on commit 316da26

Please sign in to comment.