微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用Python将Exif DMS转换为DD Geolocation

如何解决使用Python将Exif DMS转换为DD Geolocation

| 我正在使用以下代码提取使用iPhone拍摄的图像的地理位置:
from PIL import Image
from PIL.ExifTags import TAGS

def get_exif(fn):
    ret = {}
    i = Image.open(fn)
    info = i._getexif()
    for tag,value in info.items():
        decoded = TAGS.get(tag,tag)
        ret[decoded] = value
    return ret

a = get_exif(\'photo2.jpg\')
print a
这是我返回的结果:
    {
    \'YResolution\': (4718592,65536),41986: 0,41987: 0,41990: 0,\'Make\': \'Apple\',\'Flash\': 32,\'ResolutionUnit\': 2,\'GPSInfo\': {
        1: \'N\',2: ((32,1),(4571,100),(0,1)),3: \'W\',4: ((117,(878,7: ((21,(47,(3712,100))
    },\'MeteringMode\': 1,\'XResolution\': (4718592,\'ExposureProgram\': 2,\'ColorSpace\': 1,\'ExifImageWidth\': 1600,\'DateTimeDigitized\': \'2011:03:01 13:47:39\',\'ApertureValue\': (4281,1441),316: \'Mac OS X 10.6.6\',\'SensingMethod\': 2,\'FNumber\': (14,5),\'DateTimeOriginal\': \'2011:03:01 13:47:39\',\'ComponentsConfiguration\': \'\\x01\\x02\\x03\\x00\',\'ExifOffset\': 254,\'ExifImageHeight\': 1200,\'Model\': \'iPhone 3G\',\'DateTime\': \'2011:03:03 10:37:32\',\'Software\': \'QuickTime 7.6.6\',\'Orientation\': 1,\'FlashPixVersion\': \'0100\',\'ycbcrPositioning\': 1,\'ExifVersion\': \'0220\'
}
因此,我想知道如何将GPSInfo值(DMS)转换为实际坐标的十进制度吗?另外,似乎有两个Wests被列出。 。 。 ?     

解决方法

        这是一种方法,适用于我几个月前使用pyexiv2编写的脚本:
a = get_exif(\'photo2.jpg\')
lat = [float(x)/float(y) for x,y in a[\'GPSInfo\'][2]]
latref = a[\'GPSInfo\'][1]
lon = [float(x)/float(y) for x,y in a[\'GPSInfo\'][4]]
lonref = a[\'GPSInfo\'][3]

lat = lat[0] + lat[1]/60 + lat[2]/3600
lon = lon[0] + lon[1]/60 + lon[2]/3600
if latref == \'S\':
    lat = -lat
if lonref == \'W\':
    lon = -lon
这为我的图片提供了以下经度和纬度:32.7618333,-117.146333(与Lance Lee相同的结果)。 GPSInfo的最后一个条目可能是图片的标题。您可以使用为不同的EXIF值提供正确名称的工具(例如exiv2或exiftools)进行检查。     ,        http://www.exiv2.org/tags.html 在该页面中找到字符串\'Exif.GPSInfo.GPSLatitude \'。 看来您得到3对(代表理性),而对中的第二个数字是分母。 我希望经度后的东西可以是高度,但是它更适合GPS时间戳。 在此示例中:
32/1 + (4571 / 100)/60 + (0 / 1)/3600 = 32.761833 N
117/1 + (878 / 100)/60 + (0 / 1)/3600 = 117.146333 W
这张照片是在加利福尼亚州116116的圣地亚哥4646 Park Blvd附近拍摄的吗?如果不是,则忽略此答案。     

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。