首先要安装ExifRead

pip3 install ExifRead
pic=r’D:\S072003Python\input\test\test.jpg’
import exifread
f = open(pic, ‘rb’)
tags = exifread.process_file(f)
print(tags) #内有相机型号,拍摄时间,经纬度等

python获取图像高宽通道数_python获取图像高宽通道数

tags

python获取图像高宽通道数_Image_02

print(tags)和tags获取数据的格式不同。

tags[‘Image ImageWidth’]
tags[‘Image ImageLength’]
tags[‘Image ExifOffset’]
tags[‘Image Orientation’]
tags[‘Image DateTime’]
tags[‘EXIF WhiteBalance’]
tags[‘EXIF ISOSpeedRatings’]
tags[‘EXIF FocalLength’]
tags[‘EXIF Flash’]
tags[‘EXIF LightSource’]
exifcolumns=[‘Image ImageWidth’,‘Image ImageLength’,‘Image ExifOffset’,‘Image Orientation’,‘Image DateTime’,‘EXIF WhiteBalance’,‘EXIF ISOSpeedRatings’,‘EXIF FocalLength’,‘EXIF Flash’,‘EXIF LightSource’] # 把要提取的数据都封装在列表当中
for i in range(len(exifcolumns)):
print(tags[exifcolumns[i]]) # 使用循环拿到所有的数据

python获取图像高宽通道数_Image_03

二、循环遍历图片信息

========================================================================

任务:一次性获得以下图片的"Image ImageWidth"信息。写一个循环即可:

python获取图像高宽通道数_python_04

import exifread
import os
import pandas as pd
import glob
pic_list=glob.glob(r’C:\Users\Lenovo\Pictures\Saved Pictures*.jpg’) # 如果是png,jpeg,bmp等数据格式,如何设置?
for i in pic_list:
fr=open(i,‘rb’)
tags=exifread.process_file(fr)
if “Image ImageWidth” in tags: # 条件判断,因为并不是所有的照片都有"Image ImageWidth"
print(tags[“Image ImageWidth”])