code
import os import cv2 def compress(dirname): for filename in os.listdir(dirname): f=os.path.join(dirname,filename) img=cv2.imread(f,2) cv2.imwrite(f,img,[cv2.IMWRITE_PNG_COMPRESSION,1]) pwd=os.getcwd() w_path=os.path.join(pwd,"pic") compress(w_path)