基于Python 从一个文件夹读取照片,修改尺寸后重命名存入另一个文件夹

import cv2
import os
import numpy as np
 
def resize():
	path = 'D:\src'
	d_path = 'D:\save_image'
	filelist = os.listdir(path)
	i = 1
	for item in filelist:
		if item.endswith('.jpg'):
			src = os.path.join(os.path.abspath(path), item)
			dst = os.path.join(os.path.abspath(d_path), ''+str(i) + '.jpg')
			i += 1
			src_img = cv2.imdecode(np.fromfile(src,dtype = np.uint8),-1)
			dest_img = cv2.resize(src_img,(64,64),interpolation = cv2.INTER_CUBIC)
			cv2.imwrite(dst,dest_img)
   
if __name__ == "__main__":
    resize()

 

你可能感兴趣的:(opencv3,Python)