From 1538fad36f27fe748a3750796a5e486920124a9a Mon Sep 17 00:00:00 2001 From: Bubbliiiing <47347516+bubbliiiing@users.noreply.github.com> Date: Sun, 26 Jul 2020 21:17:02 +0800 Subject: [PATCH] Update utils.py --- utils/utils.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/utils/utils.py b/utils/utils.py index e56cd45..14fceba 100644 --- a/utils/utils.py +++ b/utils/utils.py @@ -6,6 +6,8 @@ import keras.backend as K from functools import reduce from PIL import Image from matplotlib.colors import rgb_to_hsv, hsv_to_rgb +import cv2 + def compose(*funcs): if funcs: return reduce(lambda f, g: lambda *a, **kw: g(f(*a, **kw)), funcs) @@ -142,15 +144,16 @@ def get_random_data_with_Mosaic(annotation_line, input_shape, max_boxes=50, hue= hue = rand(-hue, hue) sat = rand(1, sat) if rand()<.5 else 1/rand(1, sat) val = rand(1, val) if rand()<.5 else 1/rand(1, val) - x = rgb_to_hsv(np.array(image)/255.) - x[..., 0] += hue + x = cv2.cvtColor(np.array(image,np.float32)/255, cv2.COLOR_RGB2HSV) + x[..., 0] += hue*360 x[..., 0][x[..., 0]>1] -= 1 x[..., 0][x[..., 0]<0] += 1 x[..., 1] *= sat x[..., 2] *= val - x[x>1] = 1 + x[x[:,:, 0]>360, 0] = 360 + x[:, :, 1:][x[:, :, 1:]>1] = 1 x[x<0] = 0 - image = hsv_to_rgb(x) + image = cv2.cvtColor(x, cv2.COLOR_HSV2RGB) # numpy array, 0 to 1 image = Image.fromarray((image*255).astype(np.uint8)) # 将图片进行放置,分别对应四张分割图片的位置 @@ -237,15 +240,16 @@ def get_random_data(annotation_line, input_shape, max_boxes=50, jitter=.3, hue=. hue = rand(-hue, hue) sat = rand(1, sat) if rand()<.5 else 1/rand(1, sat) val = rand(1, val) if rand()<.5 else 1/rand(1, val) - x = rgb_to_hsv(np.array(image)/255.) - x[..., 0] += hue + x = cv2.cvtColor(np.array(image,np.float32)/255, cv2.COLOR_RGB2HSV) + x[..., 0] += hue*360 x[..., 0][x[..., 0]>1] -= 1 x[..., 0][x[..., 0]<0] += 1 x[..., 1] *= sat x[..., 2] *= val - x[x>1] = 1 + x[x[:,:, 0]>360, 0] = 360 + x[:, :, 1:][x[:, :, 1:]>1] = 1 x[x<0] = 0 - image_data = hsv_to_rgb(x) # numpy array, 0 to 1 + image_data = cv2.cvtColor(x, cv2.COLOR_HSV2RGB) # numpy array, 0 to 1 # 将box进行调整 box_data = np.zeros((max_boxes,5)) -- GitLab