问题描述:
我使用exifread模块读取图片的GPS信息,但由于GPS坐标的精度太高(如图),读取出来的坐标小数点后以分数显示,我需要完整的数据。另外请教使用Image读取GPS数据的方法(photo.info没用明白)
import os
import os.path
import exifread
import csv
workspace = r'G:\20210727' # 此处输入飞行当天文件夹路径
PhotoName = [] # 图片名
PhotosPath = [] # 图片路径列表
Bs = []
Ls = []
Hs = []
i = 0 # 图片总数
def creation_pos(path): # 以架次文件名创建POS文件
for root, dirs, flies in os.walk(path):
for FileName in dirs:
pos_name = os.path.join(path, FileName)
file = open(pos_name + '.csv', 'w') # 创建以架次名命名的csv文件
file.close()
def get_path(path): # 递归获取.JPG文件路径,并写入PhotosPath列表
global PhotosPath, i
parents = os.listdir(path)
for parent in parents:
f = os.path.join(path, parent)
if os.path.isdir(f):
get_path(f)
else:
if f.endswith('.JPG'):
PhotosPath.append(f) # 将图片路径添加至图片列表
i += 1
print(i)
get_path(workspace)
for Photo1 in PhotosPath:
name = os.path.basename(Photo1)
PhotoName .append(name)
Photo = open(Photo1, 'rb')
Photo2 = exifread.process_file(Photo)
Bs.append(Photo2['GPS GPSLatitude'])
Ls.append(Photo2['GPS GPSLongitude'])
Hs.append(Photo2['GPS GPSAltitude'])
print(Ls)
https://lexsaints.blog.csdn.net/article/details/118467097 https://lexsaints.blog.csdn.net/article/details/118467097
https://lexsaints.blog.csdn.net/article/details/116568510 https://lexsaints.blog.csdn.net/article/details/116568510
里面有详细读取流程,包括经纬度分数转成百分制小数的方法。有问题,可以联系我
请立即采纳谢谢!
import exifread
import re
def FindGPSTime(filePath):
GPS={}
Data=""
f=open(filePath,'rb')
tags=exifread.process_file(f)
for tag,value in tags.items():
if re.match('GPS GPSLatitudeRef',tag):
GPS['GPSLatitudeRef(纬度标识)']=str(value)
elif re.match('GPS GPSLongitudeRef',tag):
GPS['GPSLongitudeRef(经度标识)']=str(value)
elif re.match('GPS GPSAltitudeRef',tag):
GPS['GPSAltitudeRef(高度标识)']=str(value)
elif re.match('GPS GPSLatitude',tag):
try:
match_result=re.match('\[(\w*), (\w*), (\w.*)/(\w.*)\]',str(value)).groups() #匹配临近的字符
GPS['GPSLatitude(纬度)']=int(match_result[0]),int(match_result[1]),int(match_result[2])/int(match_result[3])
except:
GPS['GPSLatitude(纬度)']=str(value)
elif re.match('GPS GPSLongitude',tag):
try:
match_result=re.match('\[(\w*), (\w*), (\w.*)/(\w.*)\]',str(value)).groups()
GPS['GPSLongitude(经度)']=[int(match_result[0]),int(match_result[1]),int(match_result[2])/int(match_result[3])]
except:
GPS['GPSLongitude(经度)']=str(value)
elif re.match('GPS GPSAltitude',tag):
GPS['GPSAltitude(高度)']=str(value)
elif re.match('Image DateTime',tag):
Data=str(value)
return {'GPS 信息':GPS,'时间信息':Data}
if __name__=='__main__':
print(FindGPSTime("照片.jpg"))