通过exifread获取图片的GPS信息
def img_exif(self,img_path):
tags = exifread.process_file(open(img_path,'rb'))
print(type(tags)) # 通过exifread.process_file获取的是一个dict
#for key,value in tags.items():
#print("The key is %s value is %s" %(key,value))
# 得知与GPS相关的keys:
# GPS GPSVersionID GPS 的版本号
# GPS GPSLatitudeRef 南北半球
# GPS GPSLatitude 纬度
# GPS GPSLongitudeRef 东西半球
# GPS GPSLongitude 经度
# GPS GPSAltitudeRef 0 = 海平面以上 1 = 海平面以下
# GPS GPSAltitude 海拔高度
# GPS GPSTimeStamp 时间戳
# GPS GPSProcessingMethod 定位方式
# GPS GPSDate 定位日期
obtain_gps = [tags['GPS GPSLongitude'], tags['GPS GPSLatitude'], tags['GPS GPSLongitudeRef'],
tags['GPS GPSLatitudeRef'], tags['GPS GPSAltitude'], tags['GPS GPSAltitudeRef']]
return obtain_gps
与exifread相关的网址链接https://pypi.org/project/ExifRead/
,该链接中对exifread库进行了详细的介绍
通过tags = exifread.process_file(open(img_path,'rb'))
语句可以获取图片的相关信息,返回的是一个dict
对于字典的访问
for key,value in tags.items():
print("The key is %s value is %s" %(key,value))
得到键和值如下所示,
The key is Image ImageWidth value is 3456
The key is Image ImageLength value is 4608
The key is Image BitsPerSample value is [8, 8, 8]
The key is Image Make value is HUAWEI
The key is Image Model value is PAR-AL00
The key is Image Orientation value is 0
The key is Image XResolution value is 72
The key is Image YResolution value is 72
The key is Image ResolutionUnit value is Pixels/Inch
The key is Image Software value is PAR-AL00 9.1.0.321(C00E320R1P1)
The key is Image DateTime value is 2019:08:27 16:37:35
The key is Image YCbCrPositioning value is Centered
The key is Image ExifOffset value is 286
The key is GPS GPSVersionID value is [2, 2, 0, 0]
The key is GPS GPSLatitudeRef value is N
The key is GPS GPSLatitude value is [34, 29, 6493103/200000]
The key is GPS GPSLongitudeRef value is E
The key is GPS GPSLongitude value is [107, 53, 52919311/1000000]
The key is GPS GPSAltitudeRef value is 0
The key is GPS GPSAltitude value is 17689/25
The key is GPS GPSTimeStamp value is [8, 37, 32]
The key is GPS GPSProcessingMethod value is GPS
The key is GPS GPSDate value is 2019:08:27
The key is Image GPSInfo value is 8518
The key is Image DeviceSettingDescription value is [105, 112, 112, 0]
The key is Thumbnail ImageWidth value is 384
The key is Thumbnail ImageLength value is 512
The key is Thumbnail Compression value is JPEG (old-style)
The key is Thumbnail Orientation value is 0
The key is Thumbnail XResolution value is 72
The key is Thumbnail YResolution value is 72
The key is Thumbnail ResolutionUnit value is Pixels/Inch
The key is Thumbnail JPEGInterchangeFormat value is</