This commit is contained in:
Glenn Jocher 2019-02-10 21:23:58 +01:00
parent 6f0086103c
commit c60bad8b10
1 changed files with 6 additions and 4 deletions

View File

@ -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] shape = img.shape[:2] # shape = [height, width]
ratio = float(height) / max(shape) # ratio = old / new ratio = float(height) / max(shape) # ratio = old / new
new_shape = (round(shape[1] * ratio), round(shape[0] * ratio)) new_shape = (round(shape[1] * ratio), round(shape[0] * ratio))
padw = (height - new_shape[0]) // 2 # width padding dw = (height - new_shape[0]) / 2 # width padding
padh = (height - new_shape[1]) // 2 # height 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.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 img = cv2.copyMakeBorder(img, top, bottom, left, right, cv2.BORDER_CONSTANT, value=color) # padded square
return img, ratio, padw, padh return img, ratio, dw, dh
def random_affine(img, targets=None, degrees=(-10, 10), translate=(.1, .1), scale=(.9, 1.1), shear=(-2, 2), def random_affine(img, targets=None, degrees=(-10, 10), translate=(.1, .1), scale=(.9, 1.1), shear=(-2, 2),