The shape attribute of the image matrix represents the size of the image, and shape returns a tuple. The first element represents the number of rows of the matrix, which is the height of the image (Y), the second tuple represents the number of columns of the matrix, which is the width of the image (X), and the third element is 3, which means that the pixel value is composed of the three primary colors of light.

import cv2 import numpy as np fn="22.jpg" if __name__ == '__main__': print('load %s as ... ' % fn) img = cv2.imread(fn) sp = img.shape print sp sz1 = sp[0]#height(rows) of image sz2 = sp[1]#width(colums) of image sz3 = sp[2]#the pixels value is made up of three primary colors print ('width: %d \nheight: %d \nnumber: %d' %(sz1,sz2,sz3))Copy the code

Load 22.jpg as… (510, 512, 3) width: 510 height: 512 number: 3

 

Welcome to pay attention to the official number: learning log of algorithm engineers, to obtain learning materials of algorithm engineers. If you have technical consultation, we will provide paid consultation, contact QQ (1762016542) or leave a message on the official account