宽高分别裁剪增强
import cv2
import numpy as np
import random
from utils.box_utils import matrix_iof
def _crop(image, boxes, labels, img_size):
#随意裁剪,裁剪到最后resize,会有放大效果,不会缩小,小目标检测无帮助
height, width, _ = image.shape
pad_image_flag = True
if boxes[0][1] == 0:
scale = random.uniform(0.3, 1.0)
crop_height = int(scale * height)
crop_width = int(scale * width)
crop_left = 0
if width != crop_width:
crop_left = random.randrange(width - crop_width)
crop_top = 0
if height != crop_height:
crop_top = random.randrange(height - crop_height)
roi = np.array((crop_left, crop