python图像重命名 + resize

import os
import shutil
import cv2


image_path = "" #图像文件夹路径
out_path = "" #图像文件的输出路径

list_image = []
def get_image(image_path):
    pathDir = os.listdir(image_path)
    for allimage in pathDir:
        temp = allimage.split(".")
        list_image.append(temp[0])
    print(list_image)
    print(len(list_image))
    
    
    
 
get_image(image_path)
list_image.sort()
 
# 图像重命名后保存
# i = 0
# for image in list_image:
#
#     shutil.copy(os.path.join(image_path, image + '.JPG'), os.path.join(out_path, str(i).zfill(4) + '.jpg'))
#     i += 1

# 读取图像resize之后保存
i = 0
for image in list_image:
    img = cv2.imread(image_path + image + '.JPG')
    # cv2.imshow("image", img)
    # cv2.waitKey(0)
    img_2 = cv2.resize(img, (3840, 2160), interpolation=cv2.INTER_AREA)
    cv2.imwrite(out_path+ str(i).zfill(4) + '.jpg', img_2)
    # shutil.copy(os.path.join(image_path, image + '.JPG'), os.path.join(out_path, image + '.JPG'))
    i += 1

你可能感兴趣的:(python,code,python)