最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
Python数据获取实现图片数据提取代码示例
时间:2022-06-25 01:11:46 编辑:袖梨 来源:一聚教程网
本篇文章小编给大家分享一下Python数据获取实现图片数据提取代码示例,文章代码介绍的很详细,小编觉得挺不错的,现在分享给大家供大家参考,有需要的小伙伴们可以来看看。
一、利用exifread提取图片的EXIF信息
exifread介绍:
EXIF信息,是可交换图像文件的缩写,是专门为数码相机的照片设定的,可以记录数码照片的属性信息和拍摄数据。EXIF可以附加于JPEG、TIFF、RIFF等文件之中,为其增加有关数码相机拍摄信息的内容和索引图或图像处理软件的版本信息。
首先要安装ExifRead:
pip3 install ExifRead
pic=r'D:S072003Pythoninputtesttest.jpg' import exifread f = open(pic, 'rb') tags = exifread.process_file(f) print(tags) #内有相机型号,拍摄时间,经纬度等
tags
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]]) # 使用循环拿到所有的数据
二、循环遍历图片信息
任务:一次性获得以下图片的"Image ImageWidth"信息。写一个循环即可:
import exifread
import os
import pandas as pd
import glob
pic_list=glob.glob(r'C:UsersLenovoPicturesSaved 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"])
# 经纬度获取
import exifread
import os
import pandas as pd
import glob
pic_list=glob.glob(r'C:UsersLenovoPicturesSaved Pictures*.jpg')
latlonlists=[]
for i in pic_list:
fr=open(i,'rb')
tags=exifread.process_file(fr)
if "GPS GPSLatitude" in tags: # 条件判断,因为并不是所有的照片都有"Image ImageWidth"
# 维度转换
lat_ref=tags["GPS GPSLatitudeRef"]
lat=tags["GPS GPSLatitude"].printable[1:-1].replace(" ","").replace("/",",").split(",")
lat=float(lat[0])+float(lat[1])/60+float(lat[2])/3600
if lat_ref in ["N"]: # 表示是南半球的数据
lat=lat*(-1)
# 经度转换
lon_ref=tags["GPS GPSLongitudeRef"]
lon=tags["GPS GPSLongitude"].printable[1:-1].replace("","").replace("/",",").split(",")
lon=float(lon[0])+float(lon[1])/60+float(lon[2])/3600
if lon_ref in ["E"]: # 表示是西半球的数据
lon=lon*(-1)
print("维度:",lat,"经度:",lon)
latlonlist=[lat,lon]
latlonlists.append(latlonlist)
相关文章
- 美女视频软件全免费-美女主播直播全免费 02-10
- 女神漫画免费阅读在线观看最新版本下载安装-女神漫画全集高清完整版免费漫画入口页面 02-10
- 豆包网页版官方入口-豆包AI人工智能在线体验 02-10
- 成何体统电视剧32集全集:高清在线观看(免下载直达) 02-10
- 学科网登录入口-中小学学科网官网电脑版 02-10
- QQ网页版扫码登录入口-QQ网页版文件传输入口 02-10




