code: def get_polygon(
      label, sample="Dynamic", img_size=None, building=False
  ):
      results = cv2.findContours(
          image=label,
          mode=cv2.RETR_TREE,
          method=cv2.CHAIN_APPROX_TC89_KCOS,
      )  # 获取内外边界，用RETR_TREE更好表示
      cv2_v = cv2.__version__.split(".")[0]
      contours = results[1] if cv2_v == "3" else results[0]  # 边界
      hierarchys = results[2] if cv2_v == "3" else results[1]  # 隶属信息
      if len(contours) != 0:  # 可能出现没有边界的情况
          polygons = []
          relas = []
          img_shape = label.shape
          for idx, (contour, hierarchy) in enumerate(
              zip(contours, hierarchys[0])
          ):
              # print(hierarchy)
              # opencv实现边界简化
              epsilon = (
                  0.005 * cv2.arcLength(contour, True)
                  if sample == "Dynamic"
                  else sample
              )
              if not isinstance(epsilon, float) and not isinstance(
                  epsilon, int
              ):
                  epsilon = 0
              # print("epsilon:", epsilon)
              if building is False:
                  # -- Douglas-Peucker算法边界简化
                  contour = cv2.approxPolyDP(
                      contour, epsilon / 10, True
                  )
              else:
                  # -- 建筑边界简化（https://github.com/niecongchong/RS-building-regularization）
                  if contour.shape[0] >= 2:
                      contour = boundary_regularization(
                          contour, img_shape, epsilon
                      )
              # -- 自定义（角度和距离）边界简化
              out = approx_poly_DIY(contour)
              # 给出关系
              rela = (
                  idx,  # own
                  hierarchy[-1] if hierarchy[-1] != -1 else None,
              )  # parent
              polygon = []
              for p in out:
                  polygon.append(p[0])
              polygons.append(polygon)  # 边界
              relas.append(rela)  # 关系
          for i in range(len(relas)):
              if relas[i][1] != None:  # 有父圈
                  for j in range(len(relas)):
                      if relas[j][0] == relas[i][1]:  # i的父圈就是j（i是j的子圈）
                          if (
                              polygons[i] is not None
                              and polygons[j] is not None
                          ):
                              min_i, min_o = __find_min_point(
                                  polygons[i], polygons[j]
                              )
                              # 改变顺序
                              polygons[i] = __change_list(
                                  polygons[i], min_i
                              )
                              polygons[j] = __change_list(
                                  polygons[j], min_o
                              )
                              # 连接
                              if min_i != -1 and len(polygons[i]) > 0:
                                  polygons[j].extend(
                                      polygons[i]
                                  )  # 连接内圈
                              polygons[i] = None
          polygons = list(filter(None, polygons))  # 清除加到外圈的内圈多边形
          if img_size is not None:
              polygons = check_size_minmax(polygons, img_size)
          return polygons
      else:
          print("没有标签范围，无法生成边界")
          return None
  
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 1 for calling a global function with example usage: get_polygon(label, sample, img_size, building) and returns: polygons, None