How to load multiple images in a numpy array ?

前端 未结 3 423
余生分开走
余生分开走 2020-12-31 00:28

How to load pixels of multiple images in a directory in a numpy array . I have loaded a single image in a numpy array . But can not figure out how to load multiple images fr

3条回答
  •  失恋的感觉
    2020-12-31 01:20

    Use OpenCV's imread() function together with os.listdir(), like

    import numpy as np
    import cv2
    import os
    
    instances = []
    
    # Load in the images
    for filepath in os.listdir('images/'):
        instances.append(cv2.imread('images/{0}'.format(filepath),0))
    
    print(type(instances[0]))
    

    class 'numpy.ndarray'

    This returns you a list (==instances) in which all the greyscale values of the images are stored. For colour images simply set .format(filepath),1.

提交回复
热议问题