code: def generate_ann(
      root_path, image_infos, preserve_vertical, val_ratio, format
  ):
      """Generate cropped annotations and label txt file.
  
      Args:
          root_path (str): The root path of the dataset
          image_infos (list[dict]): A list of dicts of the img and
              annotation information
          preserve_vertical (bool): Whether to preserve vertical texts
          val_ratio (float): Split ratio for val set
          format (str): Using jsonl(dict) or str to format annotations
      """
  
      assert val_ratio <= 1.0
  
      if val_ratio:
          image_infos = split_train_val_list(image_infos, val_ratio)
          splits = ["training", "val"]
  
      else:
          image_infos = [image_infos]
          splits = ["training"]
  
      for i, split in enumerate(splits):
          dst_image_root = osp.join(root_path, "crops", split)
          ignore_image_root = osp.join(root_path, "ignores", split)
          os.makedirs(dst_image_root, exist_ok=True)
  
          img_info = []
          for image_info in image_infos[i]:
              index = 1
              src_img_path = osp.join(
                  root_path, "imgs", 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,
              osp.join(root_path, f"{split.lower()}_label.json"),
              "textrecog",
          )
  
file_path: mmocr/tools/dataset_converters/textrecog/bid_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 6 for calling a global function with example usage: generate_ann(root_path, image_infos, preserve_vertical, val_ratio, format) without return types