code: def collect_imgur_info(
      root_path, annotation_filename, print_every=1000
  ):
      annotation_path = osp.join(
          root_path, "annotations", annotation_filename
      )
      if not osp.exists(annotation_path):
          raise Exception(
              f"{annotation_path} not exists, please check and try again."
          )
  
      annotation = mmengine.load(annotation_path)
      images = annotation["index_to_ann_map"].keys()
      img_infos = []
      for i, img_name in enumerate(images):
          if i >= 0 and i % print_every == 0:
              print(f"{i}/{len(images)}")
  
          img_path = osp.join(root_path, "imgs", img_name + ".jpg")
  
          # Skip not exist images
          if not osp.exists(img_path):
              continue
  
          img = mmcv.imread(img_path, "unchanged")
  
          # Skip broken images
          if img is None:
              continue
  
          img_info = dict(
              file_name=img_name + ".jpg",
              height=img.shape[0],
              width=img.shape[1],
          )
  
          anno_info = []
          for ann_id in annotation["index_to_ann_map"][img_name]:
              ann = annotation["ann_id"][ann_id]
  
              # The original annotation is oriented rects [x, y, w, h, a]
              box = np.fromstring(
                  ann["bounding_box"][1:-2], sep=",", dtype=float
              )
              quadrilateral = convert_oriented_box(box)
  
              xs, ys = quadrilateral[::2], quadrilateral[1::2]
              x = max(0, math.floor(min(xs)))
              y = max(0, math.floor(min(ys)))
              w = math.floor(max(xs)) - x
              h = math.floor(max(ys)) - y
              bbox = [x, y, w, h]
              segmentation = quadrilateral
  
              anno = dict(
                  iscrowd=0,
                  category_id=1,
                  bbox=bbox,
                  area=w * h,
                  segmentation=[segmentation],
              )
              anno_info.append(anno)
          img_info.update(anno_info=anno_info)
          img_infos.append(img_info)
  
      return img_infos
  
file_path: mmocr/tools/dataset_converters/textdet/imgur_converter.py
imports: import argparse
  import math
  import os.path
  import mmcv
  import mmengine
  import numpy
  from mmocr.utils import dump_ocr_data
label_desc: Use image node_id 2 for calling a global function with example usage: collect_imgur_info(root_path, annotation_filename, print_every) and returns: img_infos