import os
import cv2
content_dirs = []
resize_img_dir = r'G:\00 test\021/' # 压缩后的路径
if os.path.exists(resize_img_dir):
pass
else:
os.makedirs(resize_img_dir)
def read_directory(directory_name):
for filename in os.listdir(directory_name):
content_dirs.append(filename)
return content_dirs
def main():
Process_dir = r'G:\00 test\datacs'#这里换成你需要resize的图片文件夹名
print("-------------begin resize process-------------")
c_dirs = read_directory(Process_dir)
for c_dir in c_dirs:
pro_dir = Process_dir+'/'+c_dir
img_array = cv2.imread(pro_dir, cv2.IMREAD_COLOR)
height, width = img_array.shape[:2]
# # print(height, width)
size = (int(width * 0.1), int(height * 0.1))
resize_img = cv2.resize(img_array, size, interpolation=cv2.INTER_AREA)
# resize_img = cv2.resize(img_array, (512, 512), interpolation=cv2.INTER_CUBIC)
print("successfully resize "+c_dir)
cv2.imwrite(resize_img_dir+c_dir, resize_img)
return c_dirs
if __name__ == '__main__':
main()
print("-------------resize process finished-------------")
print("-------------请在resize_pic文件夹下获取resize后的图片-------------")