class_docstr: Randomly crop images and make sure to contain at least one intact
  instance.
docstr: Generate crop box and make sure not to crop the polygon instances.
  
  Args:
      img_size (tuple(int)): The image size (h, w).
      results (dict): The results dict.
docstr_tok: ["Generate","crop","box","and","make","sure","not","to","crop","the","polygon","instances",".","Args",":","img_size","(","tuple","(","int",")",")",":","The","image","size","(","h",",","w",")",".","results","(","dict",")",":","The","results","dict","."]
code: def sample_crop_box(self, img_size, results):
      """Generate crop box and make sure not to crop the polygon instances.
  
      Args:
          img_size (tuple(int)): The image size (h, w).
          results (dict): The results dict.
      """
  
      assert isinstance(img_size, tuple)
      h, w = img_size[:2]
  
      key_masks = results["polys"]
  
      x_valid_array = np.ones(w, dtype=np.int32)
      y_valid_array = np.ones(h, dtype=np.int32)
  
      selected_mask = key_masks[np.random.randint(0, len(key_masks))]
      selected_mask = selected_mask.reshape((-1, 2)).astype(np.int32)
      max_x_start = max(np.min(selected_mask[:, 0]) - 2, 0)
      min_x_end = min(np.max(selected_mask[:, 0]) + 3, w - 1)
      max_y_start = max(np.min(selected_mask[:, 1]) - 2, 0)
      min_y_end = min(np.max(selected_mask[:, 1]) + 3, h - 1)
  
      for mask in key_masks:
          mask = mask.reshape((-1, 2)).astype(np.int32)
          clip_x = np.clip(mask[:, 0], 0, w - 1)
          clip_y = np.clip(mask[:, 1], 0, h - 1)
          min_x, max_x = np.min(clip_x), np.max(clip_x)
          min_y, max_y = np.min(clip_y), np.max(clip_y)
  
          x_valid_array[min_x - 2 : max_x + 3] = 0
          y_valid_array[min_y - 2 : max_y + 3] = 0
  
      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 numpy
  from PIL import Image, ImageDraw
  import cv2
  from shapely.geometry import Polygon
  import math
  from ppocr.utils.poly_nms import poly_intersection
label_desc: Use image node_id 3 for calling the RandomCropPolyInstances obj's underlying member method code with example usage: obj.sample_crop_box(img_size, results) and returns: np