code: def _coarse(contour, img_shape):
      def _inline_check(point, shape, eps=5):
          x, y = point[0]
          iH, iW = shape
          if x < eps or x > iH - eps or y < eps or y > iW - eps:
              return False
          else:
              return True
  
      area = cv2.contourArea(contour)
      # S = 20
      if area < S:  # remove polygons whose area is below a threshold S
          return None
      # D = 0.3 if area < 200 else 1.0
      # TD = 0.5 if area < 200 else 0.9
      epsilon = 0.005 * cv2.arcLength(contour, True)
      contour = cv2.approxPolyDP(contour, epsilon, True)  # DP
      p_number = contour.shape[0]
      idx = 0
      while idx < p_number:
          last_point = contour[idx - 1]
          current_point = contour[idx]
          next_idx = (idx + 1) % p_number
          next_point = contour[next_idx]
          # remove edges whose lengths are below a given side length TD
          # that varies with the area of a building.
          distance = calc_distance(current_point, next_point)
          if distance < TD and not _inline_check(next_point, img_shape):
              contour = np.delete(contour, next_idx, axis=0)
              p_number -= 1
              continue
          # remove over-sharp angles with threshold α.
          # remove over-smooth angles with threshold β.
          angle = _calc_angle(last_point, current_point, next_point)
          if (ALPHA > angle or angle > BETA) and _inline_check(
              current_point, img_shape
          ):
              contour = np.delete(contour, idx, axis=0)
              p_number -= 1
              continue
          idx += 1
      if p_number > 2:
          return contour
      else:
          return None
  
file_path: PaddleSeg/EISeg/eiseg/util/regularization/rs_regularization.py
imports: import math
  import cv2
  import numpy
  from .utils import calc_distance
label_desc: Use image node_id 2 for calling a global function with example usage: _coarse(contour, img_shape) and returns: None, contour, None, False, True