code: def generate_ann(root_path, split, image_infos, preserve_vertical):
      """Generate cropped annotations and label txt file.
  
      Args:
          root_path (str): The root path of the dataset
          split (str): The split of dataset. Namely: training or test
          image_infos (list[dict]): A list of dicts of the img and
              annotation information
          preserve_vertical (bool): Whether to preserve vertical texts
      """
      dst_image_root = osp.join(root_path, "crops", split)
      ignore_image_root = osp.join(root_path, "ignores", split)
      if split == "training":
          dst_label_file = osp.join(root_path, "train_label.json")
      elif split == "test":
          dst_label_file = osp.join(root_path, "test_label.json")
      elif split == "unseen_test":
          dst_label_file = osp.join(root_path, "unseen_test_label.json")
      os.makedirs(dst_image_root, exist_ok=True)
  
      img_info = []
      for image_info in image_infos:
          index = 1
          src_img_path = osp.join(
              root_path, "imgs", split, image_info["file_name"]
          )
          image = mmcv.imread(src_img_path)
          src_img_root = image_info["file_name"].split(".")[0]
  
          for anno in image_info["anno_info"]:
              word = anno["word"]
              dst_img = crop_img(image, anno["bbox"], 0, 0)
              h, w, _ = dst_img.shape
  
              dst_img_name = f"{src_img_root}_{index}.png"
              index += 1
              # Skip invalid annotations
              if min(dst_img.shape) == 0:
                  continue
              # Skip vertical texts
              if (
                  not preserve_vertical
                  and h / w > 2
                  and split == "training"
              ):
                  dst_img_path = osp.join(
                      ignore_image_root, dst_img_name
                  )
                  mmcv.imwrite(dst_img, dst_img_path)
                  continue
  
              dst_img_path = osp.join(dst_image_root, dst_img_name)
              mmcv.imwrite(dst_img, dst_img_path)
              img_info.append(
                  {
                      "file_name": dst_img_name,
                      "anno_info": [{"text": word}],
                  }
              )
      dump_ocr_data(img_info, dst_label_file, "textrecog")
  
file_path: mmocr/tools/dataset_converters/textrecog/vintext_converter.py
imports: import argparse
  import os
  import os.path
  import mmcv
  import mmengine
  from mmocr.utils import crop_img, dump_ocr_data
label_desc: Use image node_id 5 for calling a global function with example usage: generate_ann(root_path, split, image_infos, preserve_vertical) without return types