code: def crop_img(
      src_img, box, long_edge_pad_ratio=0.4, short_edge_pad_ratio=0.2
  ):
      """Crop text region given the bounding box which might be slightly padded.
      The bounding box is assumed to be a quadrangle and tightly bound the text
      region.
  
      Args:
          src_img (np.array): The original image.
          box (list[float | int]): Points of quadrangle.
          long_edge_pad_ratio (float): The ratio of padding to the long edge. The
              padding will be the length of the short edge * long_edge_pad_ratio.
              Defaults to 0.4.
          short_edge_pad_ratio (float): The ratio of padding to the short edge.
              The padding will be the length of the long edge *
              short_edge_pad_ratio. Defaults to 0.2.
  
      Returns:
          np.array: The cropped image.
      """
      assert is_seq_of(box, (float, int))
      assert len(box) == 8
      assert 0.0 <= long_edge_pad_ratio < 1.0
      assert 0.0 <= short_edge_pad_ratio < 1.0
  
      h, w = src_img.shape[:2]
      points_x = np.clip(np.array(box[0::2]), 0, w)
      points_y = np.clip(np.array(box[1::2]), 0, h)
  
      box_width = np.max(points_x) - np.min(points_x)
      box_height = np.max(points_y) - np.min(points_y)
      shorter_size = min(box_height, box_width)
  
      if box_height < box_width:
          horizontal_pad = long_edge_pad_ratio * shorter_size
          vertical_pad = short_edge_pad_ratio * shorter_size
      else:
          horizontal_pad = short_edge_pad_ratio * shorter_size
          vertical_pad = long_edge_pad_ratio * shorter_size
  
      left = np.clip(int(np.min(points_x) - horizontal_pad), 0, w)
      top = np.clip(int(np.min(points_y) - vertical_pad), 0, h)
      right = np.clip(int(np.max(points_x) + horizontal_pad), 0, w)
      bottom = np.clip(int(np.max(points_y) + vertical_pad), 0, h)
  
      dst_img = src_img[top:bottom, left:right]
  
      return dst_img
  
imports: import cv2
  import numpy
  from mmengine.utils import is_seq_of
  from shapely.geometry import LineString, Point
  from .bbox_utils import bbox_jitter
  from .polygon_utils import sort_vertex
label_desc: Use image node_id 2 for calling a global function with example usage: crop_img(src_img, box, long_edge_pad_ratio, short_edge_pad_ratio) and returns: dst_img