Merge pull request #275 from wanghaoyang0106/master

[bug fix] potential problem if img fed to model is in rectangular shape
pull/1/head
Glenn Jocher 5 years ago committed by GitHub
commit 31b07b3550
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -679,8 +679,8 @@ def letterbox(img, new_shape=(640, 640), color=(114, 114, 114), auto=True, scale
dw, dh = np.mod(dw, 64), np.mod(dh, 64) # wh padding dw, dh = np.mod(dw, 64), np.mod(dh, 64) # wh padding
elif scaleFill: # stretch elif scaleFill: # stretch
dw, dh = 0.0, 0.0 dw, dh = 0.0, 0.0
new_unpad = new_shape new_unpad = (new_shape[1], new_shape[0])
ratio = new_shape[0] / shape[1], new_shape[1] / shape[0] # width, height ratios ratio = new_shape[1] / shape[1], new_shape[0] / shape[0] # width, height ratios
dw /= 2 # divide padding into 2 sides dw /= 2 # divide padding into 2 sides
dh /= 2 dh /= 2

@ -173,7 +173,7 @@ def xywh2xyxy(x):
def scale_coords(img1_shape, coords, img0_shape, ratio_pad=None): def scale_coords(img1_shape, coords, img0_shape, ratio_pad=None):
# Rescale coords (xyxy) from img1_shape to img0_shape # Rescale coords (xyxy) from img1_shape to img0_shape
if ratio_pad is None: # calculate from img0_shape if ratio_pad is None: # calculate from img0_shape
gain = max(img1_shape) / max(img0_shape) # gain = old / new gain = min(img1_shape[0] / img0_shape[0], img1_shape[1] / img0_shape[1]) # gain = old / new
pad = (img1_shape[1] - img0_shape[1] * gain) / 2, (img1_shape[0] - img0_shape[0] * gain) / 2 # wh padding pad = (img1_shape[1] - img0_shape[1] * gain) / 2, (img1_shape[0] - img0_shape[0] * gain) / 2 # wh padding
else: else:
gain = ratio_pad[0][0] gain = ratio_pad[0][0]

Loading…
Cancel
Save