瀏覽代碼

Add support circle shap_type on label2coco.py (#804)

* Add support circle shap_type on label2coco.py

* Fix style

Co-authored-by: Kentaro Wada <www.kentaro.wada@gmail.com>
firesh 3 年之前
父節點
當前提交
975fe115bf
共有 1 個文件被更改,包括 8 次插入0 次删除
  1. 8 0
      examples/instance_segmentation/labelme2coco.py

+ 8 - 0
examples/instance_segmentation/labelme2coco.py

@@ -129,6 +129,14 @@ def main():
                 x1, x2 = sorted([x1, x2])
                 y1, y2 = sorted([y1, y2])
                 points = [x1, y1, x2, y1, x2, y2, x1, y2]
+            if shape_type == "circle":
+                (x1, y1), (x2, y2) = points
+                r = np.linalg.norm([x2 - x1, y2 - y1])
+                n_points_circle = 12
+                i = np.arange(n_points_circle)
+                x = x1 + r * np.sin(2 * np.pi / n_points_circle * i)
+                y = y1 + r * np.cos(2 * np.pi / n_points_circle * i)
+                points = np.stack((x, y), axis=1).flatten().tolist()
             else:
                 points = np.asarray(points).flatten().tolist()