简体   繁体   English

如何正确打开文件夹中的图像以进行处理?

[英]How do I properly open an image from a folder to process it?

I need to open images and edit them.我需要打开图像并编辑它们。 But when opened, "no such file or directory" or "<ImagingCore object at 0x0000020625552F70>" comes out.但是当打开时,“没有这样的文件或目录”或“<ImagingCore object at 0x0000020625552F70>”出来了。 The path is specified correctly, checked several times.路径指定正确,检查了几次。 How do I open the image correctly?如何正确打开图像? Also how can I save an already edited image to another folder with the same name?另外,如何将已编辑的图像保存到另一个具有相同名称的文件夹中? ''' '''

    from PIL import Image
    import os
    def convertImage():
        folder_dir = "C:\проект\Images"
        for images in os.listdir(folder_dir):
        img = Image.open(images)
        img = img.convert("RGBA")

''' '''

'No such file or directory' is caused by the path. “没有这样的文件或目录”是由路径引起的。 It has backslashes, which is an escape character.它有反斜杠,这是一个转义字符。 So the correct way to define your path is:因此,定义路径的正确方法是:

folder_dir = "C:\\проект\\Images"

To save the edited image you can use:要保存编辑后的图像,您可以使用:

img.save('path/to/output/img')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM