我有以下代码,我认为可以调整指定路径中图像的大小,但是当我运行它时,没有任何效果,但是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 帮帮我
答案 0 :(得分:0)
它不执行任何操作,因为您的for循环未在文件夹中找到任何文件。您永远不会传递文件路径的“ G:\ sar”部分。