How to check dimensions of all images in a directory using python?

后端 未结 7 722
無奈伤痛
無奈伤痛 2020-12-09 05:15

I need to check the dimensions of images in a directory. Currently it has ~700 images. I just need to check the sizes, and if the size does not match a given dimension, it w

7条回答
  •  情书的邮戳
    2020-12-09 05:47

    You can also use cv2 library to check the dimensions of images.

    import cv2
    
    # read image
    img = cv2.imread('boarding_pass.png', cv2.IMREAD_UNCHANGED)
    
    # get dimensions of image
    dimensions = img.shape
    
    # height, width, number of channels in image
    height = img.shape[0]
    width = img.shape[1]
    channels = img.shape[2]
    
    print('Image Dimension    : ',dimensions)
    print('Image Height       : ',height)
    print('Image Width        : ',width)
    print('Number of Channels : ',channels)
    

提交回复
热议问题