diff --git a/utils/datasets.py b/utils/datasets.py index 00ad081c..b0ca0694 100755 --- a/utils/datasets.py +++ b/utils/datasets.py @@ -194,11 +194,13 @@ def letterbox(img, height=416, color=(0, 0, 0)): # resize a rectangular image t shape = img.shape[:2] # shape = [height, width] ratio = float(height) / max(shape) # ratio = old / new new_shape = (round(shape[1] * ratio), round(shape[0] * ratio)) - padw = (height - new_shape[0]) // 2 # width padding - padh = (height - new_shape[1]) // 2 # height padding + dw = (height - new_shape[0]) / 2 # width padding + dh = (height - new_shape[1]) / 2 # height padding + top, bottom = round(dh - 0.1), round(dh + 0.1) + left, right = round(dw - 0.1), round(dw + 0.1) img = cv2.resize(img, new_shape, interpolation=cv2.INTER_AREA) # resized, no border - img = cv2.copyMakeBorder(img, padh, padh, padw, padw, cv2.BORDER_CONSTANT, value=color) # padded square - return img, ratio, padw, padh + img = cv2.copyMakeBorder(img, top, bottom, left, right, cv2.BORDER_CONSTANT, value=color) # padded square + return img, ratio, dw, dh def random_affine(img, targets=None, degrees=(-10, 10), translate=(.1, .1), scale=(.9, 1.1), shear=(-2, 2),