Loading all images using imread from a given folder

后端 未结 8 1994
长发绾君心
长发绾君心 2021-01-30 21:48

Loading and saving images in OpenCV is quite limited, so... what is the preferred ways to load all images from a given folder? Should I search for files in that folder with .png

相关标签:
8条回答
  • 2021-01-30 22:24

    I used skimage. You can create a collection and access elements the standard way, i.e. col[index]. This will give you the RGB values.

    from skimage.io import imread_collection
    
    #your path 
    col_dir = 'cats/*.jpg'
    
    #creating a collection with the available images
    col = imread_collection(col_dir)
    
    0 讨论(0)
  • 2021-01-30 22:27

    You can also use matplotlib for this, try this out:

    import matplotlib.image as mpimg
    
    def load_images(folder):
        images = []
        for filename in os.listdir(folder):
            img = mpimg.imread(os.path.join(folder, filename))
            if img is not None:
                images.append(img)
        return images
    
    0 讨论(0)
提交回复
热议问题