diff --git a/utils/datasets.py b/utils/datasets.py index 1f9b9e3f..fee8ceab 100755 --- a/utils/datasets.py +++ b/utils/datasets.py @@ -530,8 +530,9 @@ def load_image(self, index): def augment_hsv(img, hgain=0.5, sgain=0.5, vgain=0.5): - x = (np.random.uniform(-1, 1, 3) * np.array([hgain, sgain, vgain]) + 1).astype(np.float32) # random gains - img_hsv = (cv2.cvtColor(img, cv2.COLOR_BGR2HSV) * x.reshape((1, 1, 3))).clip(None, 255).astype(np.uint8) + x = np.random.uniform(-1, 1, 3) * [hgain, sgain, vgain] + 1 # random gains + img_hsv = (cv2.cvtColor(img, cv2.COLOR_BGR2HSV) * x).clip(None, 255).astype(np.uint8) + np.clip(img_hsv[:, :, 0], None, 179, out=img_hsv[:, :, 0]) # inplace hue clip (0 - 179 deg) cv2.cvtColor(img_hsv, cv2.COLOR_HSV2BGR, dst=img) # no return needed