in models/01_YoloV5/01_Pytorch/processing.py [0:0]
def pre_process(self, image):
pad_y, pad_x = 0, 0
if self.keep_ratio:
# Make the image square if needed by adding extra pads to
# preserve the original height to width ratio after resize
h, w = image.shape[:2]
if h != w:
max_size = max(h, w)
pad_y, pad_x = max_size - h, max_size - w
img = np.zeros((max_size, max_size, 3), dtype="float32")
img[0:max_size-pad_y, 0:max_size-pad_x] = image[:]
image = img
img = cv2.resize(image, (self.input_shape[0], self.input_shape[1]))
img = img.astype(np.float32) / 255.
# Convert to an expected shape
img = img.transpose(2, 0, 1) # to CHW
img = np.expand_dims(img, axis=0).copy() # Must use a copy here, otherwise it may not work as expected on Panorama
return img