python获取图片坐标_python提取照片坐标信息的实例代码
python提取照片坐标信息的代码如下所示:
from PIL import Image
from PIL.ExifTags import TAGS
import os
output="Z://result.csv"
out=open(output,'a')
out.write('lat,lon\n')
fpath="Z://iphonephoto"
for item in os.walk(fpath):
ob=item[2]
for i in ob:
name=fpath+'/'+str(i)
ret={}
try:
img=Image.open(name)
if hasattr(img,'_getexif'):
exifinfo=img._getexif()
if exifinfo !=None:
for tag,value in exifinfo.items():
decoded=TAGS.get(tag,tag)
ret[decoded]=value
N1 = ret['GPSInfo'][2][0][0]
N2 = ret['GPSInfo'][2][1][0]
N3 = ret['GPSInfo'][2][2][0]
N=int(N1)+int(N2)*(1.0/60)+int(N3)*(1.0/360000)
E1 = ret['GPSInfo'][4][0][0]
E2 = ret['GPSInfo'][4][1][0]
E3 = ret['GPSInfo'][4][2][0]
E=int(E1)+int(E2)*(1.0/60)+int(E3)*(1.0/360000)
out.write(str(N)+','+str(E)+'\n')
except:
pass
out.close()
PS: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获取图片坐标_python提取照片坐标信息的实例代码相关推荐
- python获取图片名称_python提取图像的名字*.jpg到txt文本的方法
如下所示: # -*- coding:utf-8 -*- import sys sys.path.append('E:\\Anaconda\\libs') import os #os:操作系统相关的信 ...
- python 写入第二列_python读写Excel表格的实例代码(简单实用)
这篇文章主要介绍了python读写Excel表格的方法,本文通过实例代码给大家介绍的非常详细,具有一定的参考借鉴价值,需要的朋友可以参考下.需要先安装两个库:pip install xlrd.pip ...
- python输出星号等腰三角形_python打印直角三角形与等腰三角形实例代码
python打印直角三角形与等腰三角形实例代码 前言 本文通过示例给大家详细介绍了关于python打印三角形的相关,分享出来供大家参考学习,下面话不多说了,来一起看看详细的介绍吧 1.直角三角形 #i ...
- python随机颜色数字_python颜色随机生成器的实例代码
1. 代码: def random_color(number=number): color = [] intnum = [str(x) for x in np.arange(10)] #Out[138 ...
- 如何用python画七彩蟒蛇_Python实现七彩蟒蛇绘制实例代码
本文主要研究的是Python编程turtle的实例,绘制一个七彩蟒蛇..具体如下. 第2周的课后练习里,有一道题目,要求修改"蟒蛇绘制"程序,对Python 蟒蛇的每个部分采用不同 ...
- python获取图片像素点_Python 处理图片像素点的实例
###在做爬虫的时候有时需要识别验证码,但是验证码一般都有干扰物,这时需要对验证码进行预处理,效果如下: from PIL import Image import itertools img = Im ...
- python获取同花顺数据_Python提取Wind数据
果然是中文编码的问题.搞定了,新鲜出炉一个小脚本.谢谢各位大神的解答. """ @Author: wenrongli @Date: 2014-11-18 @Version ...
- python直角三角形型编程_python打印直角三角形与等腰三角形实例代码
前言 本文通过示例给大家详细介绍了关于python打印三角形的相关,分享出来供大家参考学习,下面话不多说了,来一起看看详细的介绍吧 1.直角三角形 #i控制行数j控制*的个数 for i in ran ...
- python下载图片并保存_Python爬虫获取图片并下载保存至本地的实例
1.抓取煎蛋网上的图片. 2.代码如下: import urllib.request import os #to open the url def url_open(url): req=urllib. ...
最新文章
- Windows 8部署系列PART6:准备模板计算机配置
- 185页深度报告 扒一扒AI金融的老底【附下载】
- python SQLAlchemy数据库操作
- 计算多卷积核神经网络迭代次数---分类0,6
- HDU 1561 The more ,The Better
- 如何优雅的链式取值之 MayBe 函子
- CentOS 7 gedit编辑器中文乱码解决方法
- 使用ie浏览器设置Domain无法使用session的问题解决办法
- Ubuntu16.04: 和 Windows-7 双系统启动顺序更改
- Linux 内核和 Windows 内核有什么区别?
- GPU — NVIDIA GPU 架构发展史
- 【JavaWeb】Filter案例:登录验证、敏感词汇过滤
- 最新稳定不限速百度网盘破解版工具
- 2011最新笔记本、一体机显卡性能排行
- 了解单反相机的自动对焦点
- 君康人寿2019年排名_2019中国保险公司竞争力报告出炉 君康人寿盈利能力排名第二...
- Adobe Premiere Pro cs6 精简版 0xc000007b 应用程序无法正常启动
- sa提开放系统下的虚拟新贵Virtualbox权技巧之xp_regwrite替换sethc.exe
- 运营商-银联-手机厂商,三巨头如何依次主导NFC
- HTTP协议与XML