Python调整文件夹中所有图像的大小

Python调整文件夹中所有图像的大小,python,performance,resize,Python,Performance,Resize,我有下面的代码,我认为可以在指定的路径中调整图像的大小,但是当我运行它时,什么都不起作用,但是python没有抛出任何错误,所以我不知道该怎么做。请告知。谢谢 import cv2 import numpy as np import os from PIL import Image def image_resize(folder): images = [] num_images = 0 location = folder+"_" for fil

我有下面的代码,我认为可以在指定的路径中调整图像的大小,但是当我运行它时,什么都不起作用,但是python没有抛出任何错误,所以我不知道该怎么做。请告知。谢谢

import cv2
import numpy as np
import os
from PIL import Image
def image_resize(folder):
    images = []
    num_images = 0
    location = folder+"_"
    for filename in os.listdir(folder):
        img = cv2.imread(os.path.join(folder, filename))
        if img is not None:
            new_img = np.array(Image.fromarray(img).resize((200, 200), Image.ANTIALIAS))  # Resize the images to 50 X 50
            images.append(new_img)
            num_images += 1
            cv2.imwrite("{}/{}".format(location, filename), new_img)
            return None

image_resize("2S1")
image_resize("SLICY")
image_resize("BRDM-2")
image_resize("BTR-60")
image_resize("D7")
image_resize("T62")
image_resize("ZIL131")
image_resize("ZSU-23_4")
文件夹中的所有图像:G:\sar
“帮助我”

它不起任何作用,因为for循环在文件夹中找不到任何文件。您永远不会传递文件路径的“G:\sar”部分。

我从PIL导入图像(folder=“G:\\sar”)中写入和,然后写入(for),但不负责将打印语句放在for循环中,以查看循环是否正在执行