Parcourir la source

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 il y a 3 ans
Parent
commit
975fe115bf
1 fichiers modifiés avec 8 ajouts et 0 suppressions
  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()