簡體   English   中英

os.walk不將圖像保存在子目錄中

[英]os.walk not saving images in sub directories

Images是一個文件夾,其中有10個以上的子文件夾,每個子文件夾都有一個圖像,我正在將其調整大小並保存在同一位置,但是os.walk無法正常工作,任何人都可以檢查我做錯了什么。

path='E:/Dataset_Final/Images/'
def count_em(path):
    for root, dirs, files in sorted(os.walk(path)):
        for file_ in files:
            full_file_path = os.path.join(root, file_)
            print (full_file_path)
            img = Image.open(full_file_path)
            new_width  = 32
            new_height = 32
            img = img.resize((new_width, new_height), Image.ANTIALIAS)
            img.save(os.path.join(root, file_+''),'png')
        return 
count_em(path)

您在第一個目錄之后return

刪除return語句,您的代碼應按預期工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM