code: def approx_poly_DIY(contour, min_dist=10, ang_err=5):
      # print(contour.shape)  # N, 1, 2
      cs = [contour[i][0] for i in range(contour.shape[0])]
      ## 1. 先删除两个相近点与前后两个点角度接近的点
      i = 0
      while i < len(cs):
          try:
              j = (i + 1) if (i != len(cs) - 1) else 0
              if __cal_dist(cs[i], cs[j]) < min_dist:
                  last = (i - 1) if (i != 0) else (len(cs) - 1)
                  next = (j + 1) if (j != len(cs) - 1) else 0
                  ang_i = __cal_ang(cs[last], cs[i], cs[next])
                  ang_j = __cal_ang(cs[last], cs[j], cs[next])
                  # print(ang_i, ang_j)  # 角度值为-180到+180
                  if abs(ang_i - ang_j) < ang_err:
                      # 删除距离两点小的
                      dist_i = __cal_dist(cs[last], cs[i]) + __cal_dist(
                          cs[i], cs[next]
                      )
                      dist_j = __cal_dist(cs[last], cs[j]) + __cal_dist(
                          cs[j], cs[next]
                      )
                      if dist_j < dist_i:
                          del cs[j]
                      else:
                          del cs[i]
                  else:
                      i += 1
              else:
                  i += 1
          except:
              i += 1
      ## 2. 再删除夹角接近180度的点
      i = 0
      while i < len(cs):
          try:
              last = (i - 1) if (i != 0) else (len(cs) - 1)
              next = (i + 1) if (i != len(cs) - 1) else 0
              ang_i = __cal_ang(cs[last], cs[i], cs[next])
              if abs(ang_i) > (180 - ang_err):
                  del cs[i]
              else:
                  i += 1
          except:
              # i += 1
              del cs[i]
      res = np.array(cs).reshape([-1, 1, 2])
      return res
  
file_path: PaddleSeg/EISeg/eiseg/util/polygon.py
imports: from enum import Enum
  import cv2
  import numpy
  import math
  from .regularization import boundary_regularization
label_desc: Use image node_id 6 for calling a global function with example usage: approx_poly_DIY(contour, min_dist, ang_err) and returns: res