【问题标题】:how to iterate a folder containing jpg images and create a list of label and images in python? file name --> label.count.jpg如何迭代包含 jpg 图像的文件夹并在 python 中创建标签和图像列表?文件名 --> label.count.jpg
【发布时间】:2020-10-14 05:55:03
【问题描述】:

我的代码,

def loadImages(path):
    imageList = listdir(path)
    loadedImages = []
    for image in imagesList:
        img = PImage.open(path + image)
        loadedImages.append(img)
    return loadedImages

path = os.listdir('.')

imgs = loadImages(path)

for img in imgs:
    img.show()

错误:

----------------------------------- ---------------------------- TypeError Traceback(最近一次调用 最后)在 ----> 1 imgs = loadImages(路径) 2 3 用于 imgs 中的 img: 4 img.show()

在 loadImages(路径) 1 def loadImages(路径): 2 ----> 3 imageList = listdir(路径) 4 加载图像 = [] 5 用于 imagesList 中的图像:

TypeError: listdir: path 应该是 string, bytes, os.PathLike or None, 不列出

【问题讨论】:

    标签: python image label classification


    【解决方案1】:
    def loadimages(pathlist):
        loadedImages = []
        for image in pathlist:
            img = PIL.Image.open(image)
            loadedImages.append(img)
        return loadedImages
    
    
    files = os.listdir("./")
    
    labels = [i.split(".")[0] for i in files]
    images = loadimages(files)
    

    【讨论】:

      猜你喜欢
      • 2020-01-12
      • 2014-03-13
      • 1970-01-01
      • 2012-03-21
      • 1970-01-01
      • 2021-02-21
      • 2021-12-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多