| 148 | |
| 149 | |
| 150 | def _distort(image): |
| 151 | def _convert(image, alpha=1, beta=0): |
| 152 | tmp = image.astype(float) * alpha + beta |
| 153 | tmp[tmp < 0] = 0 |
| 154 | tmp[tmp > 255] = 255 |
| 155 | image[:] = tmp |
| 156 | |
| 157 | image = image.copy() |
| 158 | |
| 159 | if random.randrange(2): |
| 160 | _convert(image, beta=random.uniform(-32, 32)) |
| 161 | |
| 162 | if random.randrange(2): |
| 163 | _convert(image, alpha=random.uniform(0.5, 1.5)) |
| 164 | |
| 165 | image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV) |
| 166 | |
| 167 | if random.randrange(2): |
| 168 | tmp = image[:, :, 0].astype(int) + random.randint(-18, 18) |
| 169 | tmp %= 180 |
| 170 | image[:, :, 0] = tmp |
| 171 | |
| 172 | if random.randrange(2): |
| 173 | _convert(image[:, :, 1], alpha=random.uniform(0.5, 1.5)) |
| 174 | |
| 175 | image = cv2.cvtColor(image, cv2.COLOR_HSV2BGR) |
| 176 | |
| 177 | return image |
| 178 | |
| 179 | |
| 180 | def _mirror(image, boxes): |