整个代码参考:bubbliiiing/object-detection-augmentation。
random_data.py
import cv2
import numpy as np
from PIL import Image, ImageDrawdef rand(a=0, b=1):return np.random.rand()*(b-a) + adef get_random_data(annotation_line, input_shape, jitter=.3, hue=.1, sat=0.7, val=0.4, random=True):line = annotation_line.split()#------------------------------## 读取图像并转换成RGB图像#------------------------------#image = Image.open(line[0])image = image.convert('RGB')#------------------------------## 获得图像的高宽与目标高宽#------------------------------#iw, ih = image.sizeh, w = input_shape#------------------------------## 获得预测框#------------------------------#box = np.arra