Skip to content

Instantly share code, notes, and snippets.

@teshanshanuka
Created April 19, 2021 19:14
Show Gist options
  • Save teshanshanuka/ce08d29c4d434982413d7b64038a76b9 to your computer and use it in GitHub Desktop.
Save teshanshanuka/ce08d29c4d434982413d7b64038a76b9 to your computer and use it in GitHub Desktop.
Reduce image quality
import cv2
import os
from tqdm import tqdm
ipdir = 'Camera'
opdir = 'CamLow'
out_quality = 70
fmt = ('.jpg', '.jpeg', '.png')
for f in tqdm([_f for _f in os.listdir(ipdir) if _f.endswith(fmt)]):
img = cv2.imread(os.path.join(ipdir, f))
try:
cv2.imwrite(os.path.join(opdir, f), img, [int(cv2.IMWRITE_JPEG_QUALITY), out_quality])
except:
raise RuntimeError(f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment