class_docstr: Randomly crop images and make sure to contain at least one intact
  instance.
  
  Required Keys:
  
  - img
  - gt_polygons
  - gt_bboxes
  - gt_bboxes_labels
  - gt_ignored
  - gt_texts (optional)
  
  Modified Keys:
  
  - img
  - img_shape
  - gt_polygons
  - gt_bboxes
  - gt_bboxes_labels
  - gt_ignored
  - gt_texts (optional)
  
  Args:
      min_side_ratio (float): The ratio of the shortest edge of the cropped
          image to the original image size.
class_docstr_tok: ["Randomly","crop","images","and","make","sure","to","contain","at","least","one","intact","instance",".","Required","Keys",":","-","img","-","gt_polygons","-","gt_bboxes","-","gt_bboxes_labels","-","gt_ignored","-","gt_texts","(","optional",")","Modified","Keys",":","-","img","-","img_shape","-","gt_polygons","-","gt_bboxes","-","gt_bboxes_labels","-","gt_ignored","-","gt_texts","(","optional",")","Args",":","min_side_ratio","(","float",")",":","The","ratio","of","the","shortest","edge","of","the","cropped","image","to","the","original","image","size","."]
docstr: Generate crop box which only contains intact polygon instances with
  the number >= 1.
  
  Args:
      img_size (tuple(int, int)): The image size (h, w).
      results (dict): The results dict.
  
  Returns:
      ndarray: Crop area in shape (4, ).
docstr_tok: ["Generate","crop","box","which","only","contains","intact","polygon","instances","with","the","number",">","=","1",".","Args",":","img_size","(","tuple","(","int",",","int",")",")",":","The","image","size","(","h",",","w",")",".","results","(","dict",")",":","The","results","dict",".","Returns",":","ndarray",":","Crop","area","in","shape","(","4",",",")","."]
code: def _sample_crop_box(
      self, img_size: Tuple[int, int], results: Dict
  ) -> np.ndarray:
      """Generate crop box which only contains intact polygon instances with
      the number >= 1.
  
      Args:
          img_size (tuple(int, int)): The image size (h, w).
          results (dict): The results dict.
  
      Returns:
          ndarray: Crop area in shape (4, ).
      """
      assert isinstance(img_size, tuple)
      h, w = img_size[:2]
  
      # Crop box can be represented by any integer numbers in
      # range [0, w] and [0, h]
      x_valid_array = np.ones(w + 1, dtype=np.int32)
      y_valid_array = np.ones(h + 1, dtype=np.int32)
  
      polygons = results["gt_polygons"]
  
      # Randomly select a polygon that must be inside
      # the cropped region
      kept_poly_idx = np.random.randint(0, len(polygons))
      for i, polygon in enumerate(polygons):
          polygon = polygon.reshape((-1, 2))
  
          clip_x = np.clip(polygon[:, 0], 0, w)
          clip_y = np.clip(polygon[:, 1], 0, h)
          min_x = np.floor(np.min(clip_x)).astype(np.int32)
          min_y = np.floor(np.min(clip_y)).astype(np.int32)
          max_x = np.ceil(np.max(clip_x)).astype(np.int32)
          max_y = np.ceil(np.max(clip_y)).astype(np.int32)
  
          x_valid_array[min_x:max_x] = 0
          y_valid_array[min_y:max_y] = 0
  
          if i == kept_poly_idx:
              max_x_start = min_x
              min_x_end = max_x
              max_y_start = min_y
              min_y_end = max_y
  
      min_w = int(w * self.min_side_ratio)
      min_h = int(h * self.min_side_ratio)
  
      x1, x2 = self._sample_valid_start_end(
          x_valid_array, min_w, max_x_start, min_x_end
      )
      y1, y2 = self._sample_valid_start_end(
          y_valid_array, min_h, max_y_start, min_y_end
      )
  
      return np.array([x1, y1, x2, y2])
  
imports: import math
  from typing import Dict, Tuple
  import cv2
  import mmcv
  import numpy
  from mmcv.transforms import Resize
  from mmcv.transforms.base import BaseTransform
  from mmcv.transforms.utils import avoid_cache_randomness, cache_randomness
  from mmocr.registry import TRANSFORMS
  from mmocr.utils import bbox2poly, crop_polygon, is_poly_inside_rect, poly2bbox, poly2shapely, poly_make_valid, remove_pipeline_elements, rescale_polygon, shapely2poly
  from .wrappers import ImgAugWrapper
label_desc: Use image node_id 3 for calling the RandomCrop obj's underlying member method code with example usage: obj._sample_crop_box(img_size, results) and returns: np