Ax *_*x M 1 python gps exif python-imaging-library pyexiv2
我正在尝试从JPG图像中提取 GPS 坐标,但我没有获得太多信息pillow。
这是我的第一次尝试:
from PIL import Image
from PIL.ExifTags import TAGS
my_img = Image.open("IMG_0547.jpg")
exif_data = my_img.getexif()
for tag_id in exif_data:
tag = TAGS.get(tag_id, tag_id)
data = exif_data.get(tag_id)
print(f"{tag:16}: {data}")
Run Code Online (Sandbox Code Playgroud)
输出:
TileWidth : 512
TileLength : 512
GPSInfo : 1996
ResolutionUnit : 2
ExifOffset : 216
Make : Apple
Model : iPhone XS
Software : 13.6
Orientation : 1
DateTime : 2020:08:13 21:01:41
XResolution : 72.0
YResolution : 72.0
Run Code Online (Sandbox Code Playgroud)
从这里下载图像
我也尝试过使用pyexiv2,但只有一行代码出现此错误
metadata = pyexiv2.ImageMetadata('IMG_0547.jpg'),这没有意义,因为ImageMetadata在官方文档中列出了这里
Traceback (most recent call last):
File "maps.py", line 17, in <module>
metadata = pyexiv2.ImageMetadata('IMG_0547.jpg')
AttributeError: module 'pyexiv2' has no attribute 'ImageMetadata'
Run Code Online (Sandbox Code Playgroud)
有人可以帮我获取坐标吗?
Pillow 的 Github 有解释。中的数字GPSInfo只是一种偏移量(请参阅https://photo.stackexchange.com/a/27724)。
要查找 的内容GPSInfo,我们可以使用PIL.Image.Exif.get_ifd:
from PIL import ExifTags, Image
GPSINFO_TAG = next(
tag for tag, name in TAGS.items() if name == "GPSInfo"
) # should be 34853
path = "my_geotagged_image.jpg"
image = Image.open(path)
info = image.getexif()
gpsinfo = info.get_ifd(GPSINFO_TAG)
Run Code Online (Sandbox Code Playgroud)
然后继续如下:Interpreting GPS info of exif data from photo in python