|
11 | 11 | from utils.utils import bbox_iou, merge_bboxes |
12 | 12 | from matplotlib.colors import rgb_to_hsv, hsv_to_rgb |
13 | 13 | from nets.yolo_training import Generator |
14 | | - |
| 14 | +import cv2 |
15 | 15 |
|
16 | 16 | class YoloDataset(Dataset): |
17 | 17 | def __init__(self, train_lines, image_size, mosaic=True): |
@@ -65,15 +65,16 @@ def get_random_data(self, annotation_line, input_shape, jitter=.3, hue=.1, sat=1 |
65 | 65 | hue = self.rand(-hue, hue) |
66 | 66 | sat = self.rand(1, sat) if self.rand() < .5 else 1 / self.rand(1, sat) |
67 | 67 | val = self.rand(1, val) if self.rand() < .5 else 1 / self.rand(1, val) |
68 | | - x = rgb_to_hsv(np.array(image) / 255.) |
69 | | - x[..., 0] += hue |
70 | | - x[..., 0][x[..., 0] > 1] -= 1 |
71 | | - x[..., 0][x[..., 0] < 0] += 1 |
| 68 | + x = cv2.cvtColor(np.array(image,np.float32)/255, cv2.COLOR_RGB2HSV) |
| 69 | + x[..., 0] += hue*360 |
| 70 | + x[..., 0][x[..., 0]>1] -= 1 |
| 71 | + x[..., 0][x[..., 0]<0] += 1 |
72 | 72 | x[..., 1] *= sat |
73 | 73 | x[..., 2] *= val |
74 | | - x[x > 1] = 1 |
75 | | - x[x < 0] = 0 |
76 | | - image_data = hsv_to_rgb(x) * 255 # numpy array, 0 to 1 |
| 74 | + x[x[:,:, 0]>360, 0] = 360 |
| 75 | + x[:, :, 1:][x[:, :, 1:]>1] = 1 |
| 76 | + x[x<0] = 0 |
| 77 | + image_data = cv2.cvtColor(x, cv2.COLOR_HSV2RGB)*255 |
77 | 78 |
|
78 | 79 | # 调整目标框坐标 |
79 | 80 | box_data = np.zeros((len(box), 5)) |
@@ -144,15 +145,16 @@ def get_random_data_with_Mosaic(self, annotation_line, input_shape, hue=.1, sat= |
144 | 145 | hue = self.rand(-hue, hue) |
145 | 146 | sat = self.rand(1, sat) if self.rand() < .5 else 1 / self.rand(1, sat) |
146 | 147 | val = self.rand(1, val) if self.rand() < .5 else 1 / self.rand(1, val) |
147 | | - x = rgb_to_hsv(np.array(image) / 255.) |
148 | | - x[..., 0] += hue |
149 | | - x[..., 0][x[..., 0] > 1] -= 1 |
150 | | - x[..., 0][x[..., 0] < 0] += 1 |
| 148 | + x = cv2.cvtColor(np.array(image,np.float32)/255, cv2.COLOR_RGB2HSV) |
| 149 | + x[..., 0] += hue*360 |
| 150 | + x[..., 0][x[..., 0]>1] -= 1 |
| 151 | + x[..., 0][x[..., 0]<0] += 1 |
151 | 152 | x[..., 1] *= sat |
152 | 153 | x[..., 2] *= val |
153 | | - x[x > 1] = 1 |
154 | | - x[x < 0] = 0 |
155 | | - image = hsv_to_rgb(x) |
| 154 | + x[x[:,:, 0]>360, 0] = 360 |
| 155 | + x[:, :, 1:][x[:, :, 1:]>1] = 1 |
| 156 | + x[x<0] = 0 |
| 157 | + image = cv2.cvtColor(x, cv2.COLOR_HSV2RGB) # numpy array, 0 to 1 |
156 | 158 |
|
157 | 159 | image = Image.fromarray((image * 255).astype(np.uint8)) |
158 | 160 | # 将图片进行放置,分别对应四张分割图片的位置 |
|
0 commit comments