From f33496500f63dd6c7c64be41edcb3e2d165fb94c Mon Sep 17 00:00:00 2001 From: Philip Gutjahr Date: Wed, 16 Mar 2022 09:13:23 +0100 Subject: [PATCH] use pillow to save higher-quality jpg (w/o color subsampling) --- utils/plots.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/utils/plots.py b/utils/plots.py index 6c3f5bcaef37..604b206ae29b 100644 --- a/utils/plots.py +++ b/utils/plots.py @@ -467,5 +467,7 @@ def save_one_box(xyxy, im, file='image.jpg', gain=1.02, pad=10, square=False, BG crop = im[int(xyxy[0, 1]):int(xyxy[0, 3]), int(xyxy[0, 0]):int(xyxy[0, 2]), ::(1 if BGR else -1)] if save: file.parent.mkdir(parents=True, exist_ok=True) # make directory - cv2.imwrite(str(increment_path(file).with_suffix('.jpg')), crop) + # use pillow to save higher-quality jpg (w/o color subsampling) + crop_pil = Image.fromarray(cv2.cvtColor(crop, cv2.COLOR_BGR2RGB)) + crop_pil.save(str(increment_path(file).with_suffix('.jpg')), quality=95, subsampling=0) return crop