python - Python:将JPG图像添加到folium中的弹出窗口
问题描述
我正在尝试使用 folium 将 jpg 图像添加到地图上的标记弹出窗口。到目前为止,我有一个程序可以扫描图像文件夹并按时间顺序在地图上绘制它们的位置。我已经阅读了这里的一些其他线程,并且我试图实现代码,但是那些处理的是单一图像而不是它们的文件夹。
我需要能够在地图上的每个标记上预览文件夹中的所有 jpg 图像。
当我运行代码时,我遇到了这个错误: FileNotFoundError: [Errno 2] No such file or directory: 'IMG_0097.jpg'
任何帮助表示赞赏,谢谢。
import os, exif, folium, base64
def convert_lat(coordinates, ref):
latCoords = coordinates[0] + coordinates[1] / 60 + coordinates[2] / 3600
if ref == 'W' or ref == 'S':
latCoords = -latCoords
return latCoords
filename=[]
coordList=[]
map = folium.Map(location=[51.50197125069916, -0.14000860301423912], zoom_start = 16)
from exif import Image
with os.scandir('gps/') as entries:
for entry in entries:
filename= [i.name for i in entries if not i.name.startswith('.')]
sortedList = sorted(filename, key=lambda x: int(x.split("_")[1].split(".")[0]))
for c in range(len(sortedList)):
img_path = ('gps/'+sortedList[c])
with open (img_path, 'rb') as src:
img = Image(src)
if img.has_exif:
latCoords = (convert_lat(img.gps_latitude, img.gps_latitude_ref))
longCoords = (convert_lat(img.gps_longitude, img.gps_longitude_ref))
coord = [latCoords, longCoords]
coordList.append(coord)
else:
print (src.name,'has no EXIF information')
count=0
for c in range(len(coordList)):
popmsg = "Count is "+str(count+1)
if count==0:
fileimg=(sortedList[c])
encoded = base64.b64encode(open(sortedList[c], 'rb').read())
html= '<img src="data:image/jpg;base64,{}">'.format
resolution, width, height = 75, 50, 25
iframe = IFrame(html(encoded), width=(width*resolution)+20, height=(height*resolution)+20)
popup = folium.Popup(iframe, max_width=1000)
folium.Marker(coordList[c],popup=popup,icon=folium.Icon(icon='home',prefix='glyphicon')).add_to(map)
elif count==(len(coordList)-1):
folium.Marker(coordList[c],popup=popmsg,icon=folium.Icon(icon='flag',prefix='glyphicon')).add_to(map)
else:
folium.Marker(coordList[c],popup=popmsg,icon=folium.Icon(icon='asterisk',prefix='glyphicon')).add_to(map)
count+= 1
folium.PolyLine(coordList, color =" red", weight=2.5, opacity=1).add_to(map)```
解决方案
推荐阅读
- php - 如何在 Laravel 8.0 中自定义登录文件名?
- pattern-matching - ReasonML 记录模式匹配的正确方法
- xml - 除了使用扩展之外,如何在 XSLT 中处理自定义命名空间?
- python - Odoo 10 收到自定义电子邮件模板渲染错误
- twilio - 如何将 Twilio-Video 房间中的单独视频文件合并为一个?
- python - 在大输入上滑动张量流分类器
- jasper-reports - 在新页面上启动 JasperReport 子报表,但在作为主报表启动时不启动
- html - Iphone7 的非全屏模式下缺少 youtube iframe 视频进度条控件(与 Ipad 一起正常工作)。野生动物园和谷歌浏览器
- excel - Excel VBA:如何在单元格中打印文本(如换行)
- amazon-web-services - 发布到另一个 AWS 账户拥有的 SNS 主题时获取 AuthorizationErrorException