python 获取图片分辨率的方法

yipeiwu_com6年前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))

以上这篇python 获取图片分辨率的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

Python中super()函数简介及用法分享

首先看一下super()函数的定义: super([type [,object-or-type]]) Return a **proxy object** that delegates m...

轻松掌握python设计模式之访问者模式

轻松掌握python设计模式之访问者模式

本文实例为大家分享了python访问者模式代码,供大家参考,具体内容如下 """访问者模式""" class Node(object): pass class A(Node):...

python 创建一个空dataframe 然后添加行数据的实例

实例如下所示: import pandas as pd import re import math dframe1 = pd.read_excel("window regulator...

Python算法之栈(stack)的实现

本文以实例形式展示了Python算法中栈(stack)的实现,对于学习数据结构域算法有一定的参考借鉴价值。具体内容如下: 1.栈stack通常的操作: Stack() 建立一个空的栈对象...

用Python展示动态规则法用以解决重叠子问题的示例

用Python展示动态规则法用以解决重叠子问题的示例

动态规划是一种用来解决定义了一个状态空间的问题的算法策略。这些问题可分解为新的子问题,子问题有自己的参数。为了解决它们,我们必须搜索这个状态空间并且在每一步作决策时进行求值。得益于这类问...