[英]Python Resize all images in a folder
我有以下代碼,我認為可以調整指定路徑中圖像的大小但是當我運行它時,沒有任何作用,但是 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”部分。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.