zoukankan      html  css  js  c++  java
  • 用python 获取照片的Exif 信息(获取拍摄设备,时间,地点等信息)

    第一步:先安装

    pip install exifread
    

     

    第二部:上代码

    import exifread
    import requests
    class PhotoExifInfo():
        def __init__(self,photo_path):
            self.photo_path = photo_path
            self.baidu_map_ak = ""
    
        def get_tags(self):
            """获取照片信息"""
            image_content = open(self.photo_path, 'rb')
            tags = exifread.process_file(image_content)
            """
            # 遍历获取照片所有信息
            for j, k in tags.items():
                print(j, k)
            """
    
    
            #打印照片其中一些信息
            print('拍摄时间:', tags['EXIF DateTimeOriginal'])
            print('照相机制造商:', tags['Image Make'])
            print('照相机型号:', tags['Image Model'])
            print('照片尺寸:', tags['EXIF ExifImageWidth'], tags['EXIF ExifImageLength'])
    
            image_content.close()
            return tags
    
        def get_lng_lat(self):
            """经纬度转换"""
            tags = self.get_tags()
            try:
                # 纬度
                LatRef = tags["GPS GPSLatitudeRef"].printable
                Lat = tags["GPS GPSLatitude"].printable[1:-1].replace(" ", "").replace("/", ",").split(",")
                Lat = float(Lat[0]) + float(Lat[1]) / 60 + float(Lat[2]) / 3600
                if LatRef != "N":
                    Lat = Lat * (-1)
                # 经度
                LonRef = tags["GPS GPSLongitudeRef"].printable
                Lon = tags["GPS GPSLongitude"].printable[1:-1].replace(" ", "").replace("/", ",").split(",")
                Lon = float(Lon[0]) + float(Lon[1]) / 60 + float(Lon[2]) / 3600
                if LonRef != "E":
                    Lon = Lon * (-1)
                return Lat,Lon
            except:
                print('Unable to get')
    
        def get_city_info(self):
            result = self.get_lng_lat()
            if result:
                Lat, Lon = result
                url = "http://api.map.baidu.com/reverse_geocoding/v3/?ak="+self.baidu_map_ak+"&output=json&coordtype=wgs84ll&location=" + str(Lat) + ',' + str(Lon)
                response = requests.get(url).json()
                status = response['status']
                if status == 0:
                    address = response['result']['formatted_address']
                    return address
                else:
                    print('baidu_map error')
    
    if __name__ == '__main__':
        result = PhotoExifInfo("IMG_20190918_080329.jpg").get_city_info()
        print("拍摄地点:{}".format(result))

    注:百度接口经纬度转换 自己可以去申请

  • 相关阅读:
    账户余额查询SQL(分类帐)
    基本值集定义
    EBS 各模块数据传送至总帐 需要运行的请求
    OU、库存组织与子库存
    AP 付款凭证
    WIP 完工入库单
    R12客户表结构分析
    ORACEL R12 总账和子账的关系
    JavaScript(转)
    ftp服务自动上传6410版子上的开发环境的设置
  • 原文地址:https://www.cnblogs.com/lvye001/p/11543889.html
Copyright © 2011-2022 走看看