python opencv批量缩放图像尺寸及批量重命名

import os
import cv2

path = "E:/JPEGImages/"

#批量缩放
# width = 1024
# height = 768
# for filename in os.listdir(path):
#     im = cv2.imread(path + filename)
#     if im.shape[1]==2592:
#         tempimg = cv2.resize(im, (width, height), cv2.INTER_LINEAR)
#         cv2.imwrite(path + filename, tempimg)

#批量重命名
for filename in os.listdir(path):
    im = cv2.imread(filename)
    name = filename.split('.')
    print(name[1])
    if name[1] == "jpg":
        os.rename(os.path.join(path, filename), os.path.join(path, name[0] + '.JPG'))

 

你可能感兴趣的:(python-opencv)