code: def seg2bbox(seg):
      """Convert segmentation to bbox.
  
      Args:
          seg (list(int | float)): A set of coordinates
      """
      if len(seg) == 4:
          min_x = min(seg[0], seg[2], seg[4], seg[6])
          max_x = max(seg[0], seg[2], seg[4], seg[6])
          min_y = min(seg[1], seg[3], seg[5], seg[7])
          max_y = max(seg[1], seg[3], seg[5], seg[7])
      else:
          seg = np.array(seg).reshape(-1, 2)
          polygon = Polygon(seg)
          min_x, min_y, max_x, max_y = polygon.bounds
      bbox = [min_x, min_y, max_x - min_x, max_y - min_y]
      return bbox
  
file_path: mmocr/tools/dataset_converters/textrecog/hiertext_converter.py
imports: import argparse
  import json
  import math
  import os.path
  from functools import partial
  import mmcv
  import mmengine
  import numpy
  from shapely.geometry import Polygon
  from mmocr.utils import dump_ocr_data
label_desc: Use image node_id 1 for calling a global function with example usage: seg2bbox(seg) and returns: bbox