当前位置:主页 > 软件编程 > Python代码 >

python 获取图片分辨率的方法

时间:2021-03-07 10:32:39 | 栏目:Python代码 | 点击:

pil版:

from PIL import Image

filename = r'E:\data\yangben\0.jpg'
img = Image.open(filename)
imgSize = img.size #图片的长和宽
print (imgSize)
maxSize = max(imgSize) #图片的长边

minSize = min(imgSize) #图片的短边
print(maxSize, minSize)

opencv版:

img = cv2.imread(F1)

sp = img.shape
height = sp[0] # height(rows) of image
width = sp[1] # width(colums) of image
chanael = sp[2] # the pixels value is made up of three primary colors
print ( 'width: %d \nheight: %d \nnumber: %d' % (width, height, chanael))

您可能感兴趣的文章:

相关文章