繁体   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