Created
April 19, 2021 19:14
-
-
Save teshanshanuka/ce08d29c4d434982413d7b64038a76b9 to your computer and use it in GitHub Desktop.
Reduce image quality
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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