code: def roi_postprocess(self, pred, img_data):
      class_list = np.unique(pred)
      result = []
      for cls_id in class_list:
          if cls_id == 0:
              continue  # skip background
          class_map = np.equal(pred, cls_id).astype(np.uint8)
  
          crop_bbox = img_data["crop_bbox"]
          bbox = img_data["bbox"]
          # get mask
          offset_left = bbox[0] - crop_bbox[0]
          offset_top = bbox[1] - crop_bbox[1]
          offset_right = offset_left + bbox[2]
          offset_bottom = offset_top + bbox[3]
          class_map = class_map[
              int(offset_top) : int(offset_bottom),
              int(offset_left) : int(offset_right),
          ].astype(np.uint8)
          contours, _ = cv2.findContours(
              class_map, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE
          )
          polygon = []
          for j in range(len(contours)):
              if len(contours[j]) <= 4:
                  continue
              contours[j][..., 0] += int(bbox[0])
              contours[j][..., 1] += int(bbox[1])
              polygon.append(contours[j].flatten().tolist())
          img_data.pop("img", None)
          img_data.pop("trans_info", None)
          img_data.pop("img_shape", None)
          img_data["polygon"] = polygon
          img_data["area"] = int(np.sum(class_map > 0))
          img_data["isNG"] = 1
          result.append(img_data)
      return result
  
file_path: PaddleSeg/contrib/QualityInspector/qinspector/seg/engine/predictor.py
imports: import numpy
  import cv2
  import paddle
  from paddleseg import utils
  from paddleseg.core import infer
  from paddleseg.core.predict import partition_list
  from paddleseg.transforms import Compose
  from paddleseg.utils import progbar
  from qinspector.utils.logger import setup_logger
label_desc: Use image node_id 3 for calling the SegPredictor obj's underlying member method code with example usage: obj.roi_postprocess(pred, img_data) and returns: result