diff --git a/utils/datasets.py b/utils/datasets.py index b042c3af..abf184a9 100755 --- a/utils/datasets.py +++ b/utils/datasets.py @@ -405,10 +405,11 @@ def letterbox(img, new_shape=416, color=(128, 128, 128), mode='auto'): new_unpad = (new_shape, new_shape) ratiow, ratioh = new_shape / shape[1], new_shape / shape[0] + if shape[::-1] != new_unpad: + img = cv2.resize(img, new_unpad, interpolation=cv2.INTER_AREA) # resize top, bottom = int(round(dh - 0.1)), int(round(dh + 0.1)) left, right = int(round(dw - 0.1)), int(round(dw + 0.1)) - img = cv2.resize(img, new_unpad, interpolation=cv2.INTER_AREA) # resized, no border - img = cv2.copyMakeBorder(img, top, bottom, left, right, cv2.BORDER_CONSTANT, value=color) # padded square + img = cv2.copyMakeBorder(img, top, bottom, left, right, cv2.BORDER_CONSTANT, value=color) # add border return img, ratiow, ratioh, dw, dh