python读取图片路径_Python小列子-读取照片位置
Python exifread
Python利用exifread库来解析照片的经纬度,对接百度地图API显示拍摄地点。
import exifread
import re
import json
import requests
def latitude_and_longitude_convert_to_decimal_system(*arg):
"""
经纬度转为小数, 作者尝试适用于iphone6、ipad2以上的拍照的照片,
:param arg:
:return: 十进制小数
"""
return float(arg[0]) + ((float(arg[1]) + (float(arg[2].split('/')[0]) / float(arg[2].split('/')[-1]) / 60)) / 60)
def find_GPS_image(pic_path):
GPS = {}
date = ''
with open(pic_path, 'rb') as f:
tags = exifread.process_file(f)
for tag, value in tags.items():
if re.match('GPS GPSLatitudeRef', tag):
GPS['GPSLatitudeRef'] = str(value)
elif re.match('GPS GPSLongitudeRef', tag):
GPS['GPSLongitudeRef'] = str(value)
elif re.match('GPS GPSAltitudeRef', tag):
GPS['GPSAltitudeRef'] = str(value)
elif re.match('GPS GPSLatitude', tag):
try:
match_result = re.match('\[(\w*),(\w*),(\w.*)/(\w.*)\]', str(value)).groups()
GPS['GPSLatitude'] = int(match_result[0]), int(match_result[1]), int(match_result[2])
except:
deg, min, sec = [x.replace(' ', '') for x in str(value)[1:-1].split(',')]
GPS['GPSLatitude'] = latitude_and_longitude_convert_to_decimal_system(deg, min, sec)
elif re.match('GPS GPSLongitude', tag):
try:
match_result = re.match('\[(\w*),(\w*),(\w.*)/(\w.*)\]', str(value)).groups()
GPS['GPSLongitude'] = int(match_result[0]), int(match_result[1]), int(match_result[2])
except:
deg, min, sec = [x.replace(' ', '') for x in str(value)[1:-1].split(',')]
GPS['GPSLongitude'] = latitude_and_longitude_convert_to_decimal_system(deg, min, sec)
elif re.match('GPS GPSAltitude', tag):
GPS['GPSAltitude'] = str(value)
elif re.match('.*Date.*', tag):
date = str(value)
return {'GPS_information': GPS, 'date_information': date}
def find_address_from_GPS(GPS):
print(GPS)
"""
使用Geocoding API把经纬度坐标转换为结构化地址。
:param GPS:
:return:
"""
secret_key = 'xxxxxxxxxxxxxxxxxxxx' # 百度地图创应用的秘钥
if not GPS['GPS_information']:
return '该照片无GPS信息'
lat, lng = GPS['GPS_information']['GPSLatitude'], GPS['GPS_information']['GPSLongitude']
baidu_map_api = "http://api.map.baidu.com/geocoder/v2/?ak={0}&callback=renderReverse&location={1},{2}s&output=json&pois=0".format(
secret_key, lat, lng)
response = requests.get(baidu_map_api)
content = response.text.replace("renderReverse&&renderReverse(", "")[:-1]
baidu_map_address = json.loads(content)
formatted_address = baidu_map_address["result"]["formatted_address"]
# province = baidu_map_address["result"]["addressComponent"]["province"]
# city = baidu_map_address["result"]["addressComponent"]["city"]
# district = baidu_map_address["result"]["addressComponent"]["district"]
return formatted_address
GPS_info = find_GPS_image(pic_path='lllll.jpg') # 照片
address = find_address_from_GPS(GPS=GPS_info)
print(address)
python读取图片路径_Python小列子-读取照片位置相关推荐
- mac系统python读取文件路径_Python小技巧:3个处理文件路径的简单方法
原标题 | Python 3 Quick Tip: The easy way to deal with file paths on Windows, Mac and Linux 作者 | Adam G ...
- python做图片美化_Python实现简单的照片磨皮(照片智能磨皮) 最新免费版
Python实现简单的照片磨皮(照片智能磨皮)是一款用python写的最好的照片磨皮软件.需要配置opencv和numpy,使用的时候地址需要加英文的引号,斜杠要用双斜杠,例如"D:\\a. ...
- python获取图片坐标_python提取照片坐标信息的实例代码
python提取照片坐标信息的代码如下所示: from PIL import Image from PIL.ExifTags import TAGS import os output="Z: ...
- java读取xml路径问题_java 中读取xml 和绝对路径
一.得到绝对路径 本人用到的不多,就列举常用的. 以上2种可读取固定配置文件可用得到绝对路径 1.System.getProperty("user.dir"); 这个东西局限性十分 ...
- python读取图片文件名_python图像处理基础之PIL和opencv
python图像处理基础 pip install pillow 安装PIL库 1.读取图片 from PIL import Image import numpy as np #打开图片 img = I ...
- python显示图片列表_python读取图片任意范围区域
使用python进行图片处理,现在需要读出图片的任意一块区域,并将其转化为一维数组,方便后续卷积操作的使用. 下面使用两种方法进行处理: convert 函数 from PIL import Imag ...
- c语言使用小技巧之读取图片路径和label
主要是我记性不好 记下这些常用的以免自己忘记. 1. 每个图片路径后面跟一个label 那么读取方式为: fstream fin; fin.open("ss.txt", ios: ...
- python导入图片数据_Python中读取图片的6种方式
Python进行图片处理,第一步就是读取图片,这里给大家整理了6种图片的读取方式,并将读取的图片装换成numpy.ndarray()格式.首先需要准备一张照片,假如你有女朋友的话,可以用女朋友的,没有 ...
- python读取图片格式_Python读取图片尺寸、图片格式
Python读取图片尺寸.图片格式 需要用到PIL模块,使用pip安装Pillow.Pillow是从PIL fork过来的Python 图片库. from PIL import Image im = ...
最新文章
- 2021.12.17自制望远镜调焦座材料
- 荆门市掇刀石中学2021高考成绩查询,2021年荆门中考所有高中学校排名 荆门重点高中分数线...
- [转]android 获取 imei号码
- 亚马逊AWS免费套餐EC2安装centos连接登录并创建root
- linux 系统 指令lis,常用Linxu系统监控命令
- JSR-303 数据校验学习
- oracle11g ora-27154 past/wait 错误解决方法
- android外接键盘,小米手机如何外接键盘
- 关于UDS诊断会话管理功能相关服务的学习笔记
- 单片机 switch c语言,单片机入门-C51语言switch-case语句电路应用实例
- python中画折线图不同颜色的两段_matplotlib绘制精美的折线图——另附颜色、形状查找表...
- Spark 之 Accumulator 累加器
- MIT-BIH心律失常数据库目录(译)
- 卸载金蝶kis记账王的方法
- 二分图 恶补定义!!!
- 什么是MySQL的复制表?
- 翻译翻译什么TMD叫EXPLAIN
- 法律权利与法律义务的二重性
- SQLite(二): Java操作SQLite
- Oracle P6 Professional专业版 22.12 中的热门新功能