| 9 | |
| 10 | # 添加jpeg压缩 |
| 11 | class JPEGCompression: |
| 12 | def __init__(self, quality=10, p=0.3): |
| 13 | self.quality = quality |
| 14 | self.p = p |
| 15 | |
| 16 | def __call__(self, img): |
| 17 | if np.random.rand() < self.p: |
| 18 | img_np = np.array(img) |
| 19 | _, buffer = cv2.imencode('.jpg', img_np[:, :, ::-1], [int(cv2.IMWRITE_JPEG_QUALITY), self.quality]) |
| 20 | jpeg_img = cv2.imdecode(buffer, 1) |
| 21 | return Image.fromarray(jpeg_img[:, :, ::-1]) |
| 22 | return img |
| 23 | |
| 24 | |
| 25 | # 原始数据增强 |
no outgoing calls
no test coverage detected