From 8be4b41b3d614c641a37ead3c7da5e452852b618 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sat, 30 Nov 2019 18:19:17 -0800 Subject: [PATCH] updates --- utils/utils.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/utils/utils.py b/utils/utils.py index 0af7e5c4..a6a2478b 100755 --- a/utils/utils.py +++ b/utils/utils.py @@ -124,11 +124,17 @@ def xywh2xyxy(x): return y -def scale_coords(img1_shape, coords, img0_shape): +def scale_coords(img1_shape, coords, img0_shape, ratio_pad=None): # Rescale coords (xyxy) from img1_shape to img0_shape - gain = max(img1_shape) / max(img0_shape) # gain = old / new - coords[:, [0, 2]] -= (img1_shape[1] - img0_shape[1] * gain) / 2 # x padding - coords[:, [1, 3]] -= (img1_shape[0] - img0_shape[0] * gain) / 2 # y padding + if ratio_pad is None: # not supplied, calculate + gain = max(img1_shape) / max(img0_shape) # gain = old / new + pad = (img1_shape[1] - img0_shape[1] * gain) / 2, (img1_shape[0] - img0_shape[0] * gain) / 2 # wh padding + else: + gain = ratio_pad[0][0] + pad = ratio_pad[1] + + coords[:, [0, 2]] -= pad[0] # x padding + coords[:, [1, 3]] -= pad[1] # y padding coords[:, :4] /= gain clip_coords(coords, img0_shape) return coords