class_docstr: Convert transforms's data format from MMDet to MMOCR.
  
  Required Keys:
  
  - gt_masks (PolygonMasks | BitmapMasks) (optional)
  - gt_ignore_flags (np.bool) (optional)
  
  Added Keys:
  
  - gt_polygons (list[np.ndarray])
  - gt_ignored (np.ndarray)
class_docstr_tok: ["Convert","transforms","'s","data","format","from","MMDet","to","MMOCR",".","Required","Keys",":","-","gt_masks","(","PolygonMasks","|","BitmapMasks",")","(","optional",")","-","gt_ignore_flags","(","np.bool",")","(","optional",")","Added","Keys",":","-","gt_polygons","(","list","[","np.ndarray","]",")","-","gt_ignored","(","np.ndarray",")"]
docstr: Convert MMDet's data format to MMOCR's data format.
  
  Args:
      results (Dict): Result dict containing the data to transform.
  
  Returns:
      (Dict): The transformed data.
docstr_tok: ["Convert","MMDet","'s","data","format","to","MMOCR","'s","data","format",".","Args",":","results","(","Dict",")",":","Result","dict","containing","the","data","to","transform",".","Returns",":","(","Dict",")",":","The","transformed","data","."]
code: def transform(self, results: Dict) -> Dict:
      """Convert MMDet's data format to MMOCR's data format.
  
      Args:
          results (Dict): Result dict containing the data to transform.
  
      Returns:
          (Dict): The transformed data.
      """
      # gt_masks -> gt_polygons
      if "gt_masks" in results.keys():
          gt_polygons = []
          gt_masks = results.pop("gt_masks")
          if len(gt_masks) > 0:
              # PolygonMasks
              if isinstance(gt_masks[0], PolygonMasks):
                  gt_polygons = [mask[0] for mask in gt_masks.masks]
              # BitmapMasks
              else:
                  polygons = []
                  for mask in gt_masks.masks:
                      contours, _ = bitmap_to_polygon(mask)
                      polygons += [
                          contour.reshape(-1) for contour in contours
                      ]
                  # filter invalid polygons
                  gt_polygons = []
                  for polygon in polygons:
                      if len(polygon) < 6:
                          continue
                      gt_polygons.append(polygon)
  
          results["gt_polygons"] = gt_polygons
      # gt_ignore_flags -> gt_ignored
      if "gt_ignore_flags" in results.keys():
          gt_ignored = results.pop("gt_ignore_flags")
          results["gt_ignored"] = gt_ignored
  
      return results
  
file_path: mmocr/mmocr/datasets/transforms/adapters.py
imports: from typing import Dict
  from mmcv.transforms.base import BaseTransform
  from mmdet.structures.mask import PolygonMasks, bitmap_to_polygon
  from mmocr.registry import TRANSFORMS
label_desc: Use image node_id 1 for calling the MMDet2MMOCR obj's underlying member method code with example usage: obj.transform(results) and returns: results