docstr: _bitmap: single map with shape (H, W),
      whose values are binarized as {0, 1}
docstr_tok: ["_bitmap",":","single","map","with","shape","(","H",",","W",")",",","whose","values","are","binarized","as","{","0",",","1","}"]
code: def polygons_from_bitmap(
      self, pred, _bitmap, dest_width, dest_height
  ):
      """
      _bitmap: single map with shape (H, W),
          whose values are binarized as {0, 1}
      """
  
      assert len(_bitmap.shape) == 2
      bitmap = _bitmap  # The first channel
      height, width = bitmap.shape
      boxes = []
      scores = []
  
      contours, _ = cv2.findContours(
          (bitmap * 255).astype(np.uint8),
          cv2.RETR_LIST,
          cv2.CHAIN_APPROX_SIMPLE,
      )
  
      for contour in contours[: self.max_candidates]:
          epsilon = 0.005 * cv2.arcLength(contour, True)
          approx = cv2.approxPolyDP(contour, epsilon, True)
          points = approx.reshape((-1, 2))
          if points.shape[0] < 4:
              continue
          # _, sside = self.get_mini_boxes(contour)
          # if sside < self.min_size:
          #     continue
          score = self.box_score_fast(pred, contour.squeeze(1))
          if self.box_thresh > score:
              continue
  
          if points.shape[0] > 2:
              box = self.unclip(points, unclip_ratio=self.unclip_ratio)
              if len(box) > 1:
                  continue
          else:
              continue
          box = box.reshape(-1, 2)
          _, sside = self.get_mini_boxes(box.reshape((-1, 1, 2)))
          if sside < self.min_size + 2:
              continue
  
          if not isinstance(dest_width, int):
              dest_width = dest_width.item()
              dest_height = dest_height.item()
  
          box[:, 0] = np.clip(
              np.round(box[:, 0] / width * dest_width), 0, dest_width
          )
          box[:, 1] = np.clip(
              np.round(box[:, 1] / height * dest_height), 0, dest_height
          )
          boxes.append(box)
          scores.append(score)
      return boxes, scores
  
file_path: PaddleOCR/benchmark/PaddleOCR_DBNet/post_processing/seg_detector_representer.py
imports: import cv2
  import numpy
  import pyclipper
  import paddle
  from shapely.geometry import Polygon
label_desc: Use image node_id 4 for calling the SegDetectorRepresenter obj's underlying member method code with example usage: obj.polygons_from_bitmap(pred, _bitmap, dest_width, dest_height) and returns: boxes,  scores