| 21 | |
| 22 | |
| 23 | def augment_hsv(img, hgain=0.015, sgain=0.7, vgain=0.4): |
| 24 | r = np.random.uniform(-1, 1, 3) * [hgain, sgain, vgain] + 1 # random gains |
| 25 | hue, sat, val = cv2.split(cv2.cvtColor(img, cv2.COLOR_BGR2HSV)) |
| 26 | dtype = img.dtype # uint8 |
| 27 | |
| 28 | x = np.arange(0, 256, dtype=np.int16) |
| 29 | lut_hue = ((x * r[0]) % 180).astype(dtype) |
| 30 | lut_sat = np.clip(x * r[1], 0, 255).astype(dtype) |
| 31 | lut_val = np.clip(x * r[2], 0, 255).astype(dtype) |
| 32 | |
| 33 | img_hsv = cv2.merge( |
| 34 | (cv2.LUT(hue, lut_hue), cv2.LUT(sat, lut_sat), cv2.LUT(val, lut_val)) |
| 35 | ).astype(dtype) |
| 36 | cv2.cvtColor(img_hsv, cv2.COLOR_HSV2BGR, dst=img) # no return needed |
| 37 | |
| 38 | |
| 39 | def box_candidates(box1, box2, wh_thr=2, ar_thr=20, area_thr=0.2): |