Skip to content

Commit

Permalink
Convert rectangle to polygon in labelme2coco.py
Browse files Browse the repository at this point in the history
  • Loading branch information
wkentaro committed May 28, 2020
1 parent ecf6362 commit 5c76add
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions examples/instance_segmentation/labelme2coco.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def main():
points = shape['points']
label = shape['label']
group_id = shape.get('group_id')
shape_type = shape.get('shape_type')
shape_type = shape.get('shape_type', 'polygon')
mask = labelme.utils.shape_to_mask(
img.shape[:2], points, shape_type
)
Expand All @@ -125,12 +125,14 @@ def main():
else:
masks[instance] = mask

points = np.asarray(points).flatten().tolist()

if shape['shape_type'] == 'rectangle':
x_1, y_1, x_2, y_2 = points
points = [x_1, y_1, x_2, y_1, x_2, y_2, x_1, y_2]

if shape_type == 'rectangle':
(x1, y1), (x2, y2) = points
x1, x2 = sorted([x1, x2])
y1, y2 = sorted([y1, y2])
points = [x1, y1, x2, y1, x2, y2, x1, y2]
else:
points = np.asarray(points).flatten().tolist()

segmentations[instance].append(points)
segmentations = dict(segmentations)

Expand Down

0 comments on commit 5c76add

Please sign in to comment.