使用Python讀取照片的GPS信息


昨天聽人說,用手機拍照會帶着GPS信息,原來沒注意過這個,因此查看下並使用代碼獲取照片里的GPS信息

查看圖片文件屬性

 

說明:

  一般手機拍照時默認會打開地理位置開關

  經過壓縮后,通常會將GPS信息壓縮掉

EXIF

  可交換圖像文件常被簡稱為EXIF(Exchangeable image file format),是專門為數碼相機的照片設定的,可以記錄數碼照片的屬性信息和拍攝數據

注:

  EXIF信息不支持png,webp等圖片格式

python通過exifread模塊獲得圖片exif信息 

ExifRead

Python library to extract EXIF data from tiff and jpeg files.

安裝

pip install exifread

讀取GPS

復制代碼
import exifread
import re

def  read():
    GPS = {}
    date = ''
    f = open("E:\\python\\IMG_20200119_145630.jpg",'rb')
    contents = exifread.process_file(f)
    for key in contents:
        if key == "GPS GPSLongitude":
            print("經度 =", contents[key],contents['GPS GPSLatitudeRef'])
        elif key =="GPS GPSLatitude":
            print("緯度 =",contents[key],contents['GPS GPSLongitudeRef'])
read()
復制代碼

運行

讀取更多信息

復制代碼
import exifread
import re

def  read():
    GPS = {}
    date = ''
    f = open("E:\\python\\IMG_20200119_145630.jpg",'rb')
    contents = exifread.process_file(f)
    for key in contents:
        if key == "GPS GPSLongitude":
            print("經度: ", contents[key],contents['GPS GPSLatitudeRef'])
            print("緯度: ",contents['GPS GPSLatitude'],contents['GPS GPSLongitudeRef'])
            print("高度基准: ",contents['GPS GPSAltitudeRef'])
            print("海拔高度: ",contents['GPS GPSAltitude'])
        if re.match('Image Make', key):
            print('品牌信息: ' , contents[key])
        if re.match('Image Model', key):
            print('具體型號: ' , contents[key])
        if re.match('Image DateTime', key):
            print('拍攝時間: ' , contents[key])
        if re.match('EXIF ExifImageWidth', key):
            print('照片尺寸: ' , contents[key],'*',contents['EXIF ExifImageLength'])
        if re.match('Image ImageDescription',key):
            print('圖像描述: ' , contents[key])
read()
復制代碼

如何防止信息被泄露 來自:https://www.cnblogs.com/baby123/p/12213794.html

傳圖的時候不要用原圖
在相機的設置里,將地理位置關掉
直接將GPS的權限關掉


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM