• 使用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的权限关掉
  • 相关阅读:
    Subsets
    Reverse Linked List II
    【转】MySQL— 进阶
    【转】MySQL— 基础
    【转】Python-面向对象进阶
    【转】python f-string
    【转】Python基础-封装与扩展、静态方法和类方法
    【转】HTML
    【转】HTTP
    【转】Python3 configparse模块(配置)
  • 原文地址:https://www.cnblogs.com/gisoracle/p/13708221.html
Copyright © 2020-2023  润新知