• 使用Python读取照片的GPS信息


    来源:https://www.cnblogs.com/baby123/p/12213794.html

    昨天听人说,用手机拍照会带着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()
    

    如何防止信息被泄露

    传图的时候不要用原图
    在相机的设置里,将地理位置关掉
    直接将GPS的权限关掉
  • 相关阅读:
    poj 1026 Cipher
    python中的global
    基于DL的文本分类综述
    K近邻算法学习
    聚类评价指标学习
    pytorch自动求导学习
    反向传播的推导
    二分搜索常用【转载】
    《Attention is all you need》论文学习
    5-28日|5-30日
  • 原文地址:https://www.cnblogs.com/lxwphp/p/15452951.html
Copyright © 2020-2023  润新知