Skip to content

Commit

Permalink
Add conversion from circle to polygon (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
raultapia committed Jan 27, 2023
1 parent 958c29d commit 74aa64a
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions labelme2coco/labelme2coco.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ def get_coco_from_labelme_folder(
coco.add_category(CocoCategory(id=category_id, name=category_name))
category_ind += 1
# parse bbox/segmentation
if shape["shape_type"] == "circle":
(cx,cy), (x1,y1) = shape["points"]
r = np.linalg.norm(np.array([x1-cx,y1-cy]))
angles = np.linspace(0,2*np.pi,50*(int(r)+1))
x = cx + r * np.cos(angles)
y = cy + r * np.sin(angles)
points = np.rint(np.append(x,y).reshape(-1,2,order='F'))
_, index = np.unique(points, return_index=True, axis=0)
shape["points"] = points[np.sort(index)]
shape["shape_type"] = "polygon"
if shape["shape_type"] == "rectangle":
x1 = shape["points"][0][0]
y1 = shape["points"][0][1]
Expand Down

0 comments on commit 74aa64a

Please sign in to comment.