|
1 | | - |
| 1 | +import cv2 |
2 | 2 | from random import shuffle |
3 | 3 | import numpy as np |
4 | 4 | import torch |
@@ -349,15 +349,16 @@ def get_random_data(self, annotation_line, input_shape, jitter=.3, hue=.1, sat=1 |
349 | 349 | hue = rand(-hue, hue) |
350 | 350 | sat = rand(1, sat) if rand()<.5 else 1/rand(1, sat) |
351 | 351 | val = rand(1, val) if rand()<.5 else 1/rand(1, val) |
352 | | - x = rgb_to_hsv(np.array(image)/255.) |
353 | | - x[..., 0] += hue |
| 352 | + x = cv2.cvtColor(np.array(image,np.float32)/255, cv2.COLOR_RGB2HSV) |
| 353 | + x[..., 0] += hue*360 |
354 | 354 | x[..., 0][x[..., 0]>1] -= 1 |
355 | 355 | x[..., 0][x[..., 0]<0] += 1 |
356 | 356 | x[..., 1] *= sat |
357 | 357 | x[..., 2] *= val |
358 | | - x[x>1] = 1 |
| 358 | + x[x[:,:, 0]>360, 0] = 360 |
| 359 | + x[:, :, 1:][x[:, :, 1:]>1] = 1 |
359 | 360 | x[x<0] = 0 |
360 | | - image_data = hsv_to_rgb(x)*255 # numpy array, 0 to 1 |
| 361 | + image_data = cv2.cvtColor(x, cv2.COLOR_HSV2RGB)*255 |
361 | 362 |
|
362 | 363 | # correct boxes |
363 | 364 | box_data = np.zeros((len(box),5)) |
@@ -428,16 +429,17 @@ def get_random_data_with_Mosaic(self, annotation_line, input_shape, hue=.1, sat= |
428 | 429 | hue = rand(-hue, hue) |
429 | 430 | sat = rand(1, sat) if rand()<.5 else 1/rand(1, sat) |
430 | 431 | val = rand(1, val) if rand()<.5 else 1/rand(1, val) |
431 | | - x = rgb_to_hsv(np.array(image)/255.) |
432 | | - x[..., 0] += hue |
| 432 | + x = cv2.cvtColor(np.array(image,np.float32)/255, cv2.COLOR_RGB2HSV) |
| 433 | + x[..., 0] += hue*360 |
433 | 434 | x[..., 0][x[..., 0]>1] -= 1 |
434 | 435 | x[..., 0][x[..., 0]<0] += 1 |
435 | 436 | x[..., 1] *= sat |
436 | 437 | x[..., 2] *= val |
437 | | - x[x>1] = 1 |
| 438 | + x[x[:,:, 0]>360, 0] = 360 |
| 439 | + x[:, :, 1:][x[:, :, 1:]>1] = 1 |
438 | 440 | x[x<0] = 0 |
439 | | - image = hsv_to_rgb(x) |
440 | | - |
| 441 | + image = cv2.cvtColor(x, cv2.COLOR_HSV2RGB) # numpy array, 0 to 1 |
| 442 | + |
441 | 443 | image = Image.fromarray((image*255).astype(np.uint8)) |
442 | 444 | # 将图片进行放置,分别对应四张分割图片的位置 |
443 | 445 | dx = place_x[index] |
|
0 commit comments