From 387bdb010db8b0669df227cd118f4d54d4a8862f Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Wed, 24 Apr 2019 19:56:04 +0200 Subject: [PATCH] updates --- utils/datasets.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/utils/datasets.py b/utils/datasets.py index 30efeb11..1dc1b7b8 100755 --- a/utils/datasets.py +++ b/utils/datasets.py @@ -277,7 +277,8 @@ def random_affine(img, targets=(), degrees=(-10, 10), translate=(.1, .1), scale= if targets is None: targets = [] border = 0 # width of added border (optional) - height = max(img.shape[0], img.shape[1]) + border * 2 + height = img.shape[0] + border * 2 + width = img.shape[1] + border * 2 # Rotation and Scale R = np.eye(3) @@ -297,7 +298,7 @@ def random_affine(img, targets=(), degrees=(-10, 10), translate=(.1, .1), scale= S[1, 0] = math.tan((random.random() * (shear[1] - shear[0]) + shear[0]) * math.pi / 180) # y shear (deg) M = S @ T @ R # Combined rotation matrix. ORDER IS IMPORTANT HERE!! - imw = cv2.warpPerspective(img, M, dsize=(height, height), flags=cv2.INTER_LINEAR, + imw = cv2.warpPerspective(img, M, dsize=(width, height), flags=cv2.INTER_LINEAR, borderValue=borderValue) # BGR order borderValue # Return warped points also @@ -326,7 +327,8 @@ def random_affine(img, targets=(), degrees=(-10, 10), translate=(.1, .1), scale= xy = np.concatenate((x - w / 2, y - h / 2, x + w / 2, y + h / 2)).reshape(4, n).T # reject warped points outside of image - np.clip(xy, 0, height, out=xy) + xy[:, [0, 2]] = xy[:, [0, 2]].clip(0, width) + xy[:, [1, 3]] = xy[:, [1, 3]].clip(0, height) w = xy[:, 2] - xy[:, 0] h = xy[:, 3] - xy[:, 1] area = w * h