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基于Tkinter模块实现的弹球小游戏

Python基于Tkinter模块实现的弹球小游戏

本文实例讲述了Python基于Tkinter模块实现的弹球小游戏。分享给大家供大家参考,具体如下: #!usr/bin/python #-*- coding:utf-8 -*- fr...

Python的GUI框架PySide的安装配置教程

Python的GUI框架PySide的安装配置教程

(一)说在前面     Python自带了GUI模块Tkinter,只是界面风格有些老旧。另外就是各种GUI框架了。    ...

用Python写一段用户登录的程序代码

用Python写一段用户登录的程序代码

如下所示: #!/usr/bin/env python #coding: utf8 import getpass db = {} def newUser(): username =...

Python 生成 -1~1 之间的随机数矩阵方法

Python 生成 -1~1 之间的随机数矩阵方法

1. 使用函数 np.random.random 由于 np.random.random() 默认生成 0~1 之间的小数,因此需要转换一下 如生成 3*3 的 -1~1 之间的随机数...

Python基于pygame实现的font游戏字体(附源码)

Python基于pygame实现的font游戏字体(附源码)

本文实例讲述了Python基于pygame实现的font游戏字体。分享给大家供大家参考,具体如下: 在pygame游戏开发中,一个友好的UI中,漂亮的字体是少不了的 今天就给大伙带来有关...