使用Python从图像中提取gps坐标

斯里尼
from PIL import Image
from PIL.ExifTags import TAGS

# path to the image or video
imagename = "image.jpg"

# read the image data using PIL
image = Image.open(imagename)

# extract EXIF data
exifdata = image.getexif()

# iterating over all EXIF data fields
for tag_id in exifdata:
    # get the tag name, instead of human unreadable tag id
    tag = TAGS.get(tag_id, tag_id)
    data = exifdata.get(tag_id)
    # decode bytes 
    if isinstance(data, bytes):
        data = data.decode()
    print(f"{tag:25}: {data}")

ExifVersion : 0220 ComponentsConfiguration : ShutterSpeedValue : (1345, 100) DateTimeOriginal : 2020:08:27 09:43:15 DateTimeDigitized : 2020:08:27 09:43:15 ApertureValue : (185, 100) Brightness ExposureBiasValue : (0, 10) MaxApertureValue : (185, 100) MeteringMode : 2 Flash : 0 FocalLength : (358, 100) UserComment : ColorSpace : 1 ExifImageWidth : 4128 SceneCaptureType : 0 SubsecTime : SubsecTime4 : SubsecTime 04Time1404222222222222222229图像长度:1908 品牌:三星型号:SM-M305F 方向:6 YCbCrPositioning:1 ExposureTime:(1, 2786) ExifInteroperabilityOffset:944 XResolution:(72, 1) FNumber:(190,SceneType):(1002) ImageUniqueID : E13LLLI00PM E13LLMK03PA

ExposureProgram:2 CustomRendered:0 ISOSpeedRatings:40 ResolutionUnit:2 ExposureMode:0 FlashPixVersion:0100 ImageWidth:4128 WhiteBalance:0 软件:M305FDDU5CTF2 DateTime:2020:08:27:05 2020 年 2 月 3 日图像长度:059:2020 年 3 月: 0 饱和度 : 0 锐度 : 0 ExifOffset : 226 MakerNote : 0100 Z@P

布鲁诺·维默伦

使用模块piexif ( pip install piexif) 您可以获取exif 中的GPS 信息,如下所示。

from pprint import pprint
from PIL import Image
import piexif

codec = 'ISO-8859-1'  # or latin-1

def exif_to_tag(exif_dict):
    exif_tag_dict = {}
    thumbnail = exif_dict.pop('thumbnail')
    exif_tag_dict['thumbnail'] = thumbnail.decode(codec)

    for ifd in exif_dict:
        exif_tag_dict[ifd] = {}
        for tag in exif_dict[ifd]:
            try:
                element = exif_dict[ifd][tag].decode(codec)

            except AttributeError:
                element = exif_dict[ifd][tag]

            exif_tag_dict[ifd][piexif.TAGS[ifd][tag]["name"]] = element

    return exif_tag_dict

def main():
    filename = 'IMG_2685.jpg'  # obviously one of your own pictures
    im = Image.open(filename)

    exif_dict = piexif.load(im.info.get('exif'))
    exif_dict = exif_to_tag(exif_dict)

    pprint(exif_dict['GPS'])

if __name__ == '__main__':
   main()

结果

{'GPSAltitude': (94549, 14993),
 'GPSAltitudeRef': 0,
 'GPSDateStamp': '2020:09:04',
 'GPSDestBearing': (1061399, 5644),
 'GPSDestBearingRef': 'T',
 'GPSHPositioningError': (5, 1),
 'GPSImgDirection': (1061399, 5644),
 'GPSImgDirectionRef': 'T',
 'GPSLatitude': ((12, 1), (34, 1), (1816, 100)),
 'GPSLatitudeRef': 'N',
 'GPSLongitude': ((99, 1), (57, 1), (4108, 100)),
 'GPSLongitudeRef': 'E',
 'GPSSpeed': (0, 1),
 'GPSSpeedRef': 'K',
 'GPSTimeStamp': ((13, 1), (2, 1), (4599, 100)),
 'GPSVersionID': (2, 2, 0, 0)}

这里exif_to_tag将 exif 代码转换为更具可读性的标签。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

在Python中从图像中提取每个像素的x,y坐标

如何使用pytesseract从图像的特定坐标中提取文本?

使用python从URL中提取图像名称

使用python从Excel文件中提取图像

使用OpenCV从图像中提取给定的多边形坐标

使用蒙版从特定坐标的图像(二维数组)中提取像素值

如何从图像中提取 (x, y) 坐标并写入 CSV 文件?

使用python从Excel工作表中提取图像

无法在python中使用pytesseract从tif图像中提取文本

使用Python从地图图像中提取建筑物边缘

使用 Python tesseract 从 PNG 图像中提取文本

使用Python OpenCV从车牌图像中提取数字和字母

如何使用Python从Google Doc中提取或读取图像

在Opencv python中使用MSER从图像中提取文本

使用 Python 从图像的背景中提取相同颜色的前景

使用python-docx从.docx文件中提取图像位置

如何使用python从图像中提取文本或数字

Python:使用 Beautiful Soup 从 HTML 标签中提取图像源

从索引中提取坐标

从GeocoderResponse中提取坐标

使用python从opencv中findcontours检测到的单个轮廓中提取坐标

使用 Python 从复杂的嵌套 Twitter json 中提取地理坐标

在Python中使用正则表达式从字符串中提取坐标

从python中的胖图像中提取文件

Python从简单图像中提取数字

Python pytesseract 从各种图像中提取数字

Python从图像opencv中提取多个对象

从Python中的字符串中提取坐标

使用Javascript从imgur中提取随机图像