Python 读取照片的信息:拍摄时间、拍摄设备、经纬度等,以及根据经纬度通过百度地图API获取位置
2023-09-11 14:21:08 时间
通过第三方库exifread读取照片信息。
exifread官网:https://pypi.org/project/ExifRead/
一、安装exifread
pip install exifread
二、读取照片信息,以及根据经纬度通过百度地图API获取位置
import exifread import json import urllib.request # Open image file for reading (binary mode) f = open('001.jpg', 'rb') # Return Exif tags tags = exifread.process_file(f) ''' #打印所有照片信息 for tag in tags.keys(): print("Key: {}, value {}".format(tag, tags[tag])) ''' #打印照片其中一些信息 print('拍摄时间:', tags['EXIF DateTimeOriginal']) print('照相机制造商:', tags['Image Make']) print('照相机型号:', tags['Image Model']) print('照片尺寸:', tags['EXIF ExifImageWidth'], tags['EXIF ExifImageLength']) #获取经度或纬度 def getLatOrLng(refKey, tudeKey): if refKey not in tags: return None ref=tags[refKey].printable LatOrLng=tags[tudeKey].printable[1:-1].replace(" ","").replace("/",",").split(",") LatOrLng=float(LatOrLng[0])+float(LatOrLng[1])/60+float(LatOrLng[2])/float(LatOrLng[3])/3600 if refKey == 'GPS GPSLatitudeRef' and tags[refKey].printable != "N": LatOrLng=LatOrLng*(-1) if refKey == 'GPS GPSLongitudeRef' and tags[refKey].printable != "E": LatOrLng=LatOrLng*(-1) return LatOrLng #调用百度地图API通过经纬度获取位置 def getlocation(lat,lng): url = 'http://api.map.baidu.com/geocoder/v2/?location=' + lat + ',' + lng + '&output=json&pois=1&ak=申请的百度地图KEY' req = urllib.request.urlopen(url) res = req.read().decode("utf-8") str = json.loads(res) #print(str) jsonResult = str.get('result') formatted_address = jsonResult.get('formatted_address') return formatted_address lat = getLatOrLng('GPS GPSLatitudeRef','GPS GPSLatitude') #纬度 lng = getLatOrLng('GPS GPSLongitudeRef','GPS GPSLongitude') #经度 print('纬度:{} 经度:{}'.format(lat, lng)) location = getlocation(str(lat), str(lng)) print('位置:{}'.format(location))
相关文章
- Python脚本抓取京东手机的配置信息
- python语法基础_01.Python基础
- 【Python】ValueError: unsupported pickle protocol: 5解决方案/同一个项目 python环境尽量保持一致
- python - 如何使用 Docker 运行多个 Python 脚本和一个可执行文件?
- Python任意参数的数量/预习课python基础
- Python 3 教程
- Eclipse Kepler SR2 + Python 3.4 + JDK7+Pydev3.4 搭建 python 开发环境(MAC)
- 零基础教你快速入门Python怎么学python入门?python新手学习路线
- 如何快速学习python,学好python?能通过Python赚到的第一笔钱,有哪些经验可以分享吗?
- 学python能做什么兼职-初学Python到月入过万最快的兼职途径(纯干货)
- 将自己OpenCV-Python-PyCharm开发环境的Python-3.6.8更换为python-3.9.10的详细过程记录
- gyp ERR! stack Error: Can‘t find Python executable “python“, you can set the PYTHON env variable.
- 【Python】【文件】查找指定路径中是否存在目标文件(含此路径下的子文件夹)
- Python 数据分析教程之如何验证线性回归的假设,线性回归的假设是什么?以及如何用python验证它们?
- Python 教程大全之使用 python 获取唯一单词的计数
- 【转载】python的魔法方法———A Guide to Python's Magic Methods
- Python 标准库
- python爬虫入门(七)Scrapy框架之Spider类
- 管理软件 食品检测 药品检测 专业化的管理软件设计与实施9 设备管理 python
- Python 基础 之 python 协程知识点整理,并实现一个简单 gevent 的协程并发图片下载的应用
- Python 工具 之 Windows 上 python 虚拟环境的搭建与简单使用的相关说明
- Python修改元组
- [Python]python+yaml三行代码完成配置文件灵活读取与warning:YAMLLoadWarning处理
- [Python]2分钟完成python + Selenium Web端自动化环境搭建,开启~~~
- Python蓝桥杯训练:基本数据结构 [链表]
- Python每日一学 04——常用数学运算函数
- Selenium4 Python实现Page Factory设计模式,python新的定位方法
- Python opencv-python 简单测试