问题描述:
我使用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)