Browse Source

Adaptively approximate the circle shape (#945)

* daptively approximate the circle shape

* Black

Co-authored-by: Joshua <fuh-d@glodon.com>
Co-authored-by: Kentaro Wada <www.kentaro.wada@gmail.com>
Joshua 3 years ago
parent
commit
a7923513b6
1 changed files with 3 additions and 1 deletions
  1. 3 1
      examples/instance_segmentation/labelme2coco.py

+ 3 - 1
examples/instance_segmentation/labelme2coco.py

@@ -132,7 +132,9 @@ def main():
             if shape_type == "circle":
                 (x1, y1), (x2, y2) = points
                 r = np.linalg.norm([x2 - x1, y2 - y1])
-                n_points_circle = 12
+                # r(1-cos(a/2))<x, a=2*pi/N => N>pi/arccos(1-x/r)
+                # x: tolerance of the gap between the arc and the line segment
+                n_points_circle = max(int(np.pi / np.arccos(1 - 1 / r)), 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)