網站首頁 編程語言 正文
? ? ? ? 從照片里面獲取GPS信息。可交換圖像文件常被簡稱為EXIF
(Exchangeable image file format),是專門為數碼相機的照片設定的,可以記錄數碼照片的屬性信息和拍攝數據,EXIF信息不支持png,webp等圖片格式。
? ? ? ? Python中使用ExifRead包讀取圖片的屬性信息,安裝方式為:
pip install exifread
? ? ? ? 使用exifread.process_file獲取圖像的信息:
img_path = r"bei_012744.jpg" f = open(img_path, 'rb') contents = exifread.process_file(f) f.close()
? ? ? ? 單步調試,contents內容如下:
GPS坐標轉換:
? ? ? ? 通過exifread獲取的經緯度信息格式通常是下面這樣的:緯度 [28, 56, 109097/5000] 經度 [112, 38, 436353/10000],轉換公式如下:
度 = 度 + 分/60 + 秒/3600?
[28, 56, 109097/5000] = 28 + 56 / 60 + 109097/5000 / 3600 = 28.93939427777778
? ? ? ? 因此坐標轉換代碼如下:
def convert_gps(coord_arr): ? ? arr = str(coord_arr).replace('[', '').replace(']', '').split(', ') ? ? d = float(arr[0]) ? ? m = float(arr[1]) ? ? s = float(arr[2].split('/')[0]) / float(arr[2].split('/')[1]) ? ? return float(d) + (float(m) / 60) + (float(s) / 3600)
? ? ? ? 完整代碼:
import exifread ? img_path = r"bei_012744.jpg" f = open(img_path, 'rb') contents = exifread.process_file(f) f.close() ? lon = contents['GPS GPSLongitude'].printable ?# 經度 lon = convert_gps(lon) lat = contents['GPS GPSLatitude'].printable ?# 緯度 lat = convert_gps(lat) altitude = contents['GPS GPSAltitude'].printable ?# 相對高度 altitude = float(altitude.split('/')[0]) / float(altitude.split('/')[1]) ? print("GPSLongitude:", lon, "\nGPSLatitude:", lat, "\naltitude:", altitude)
? ? ? ? 結果:
GPSLongitude: 112.64545425?
GPSLatitude: 28.93939427777778?
altitude: 58.009
?
原文鏈接:https://blog.csdn.net/weixin_34910922/article/details/123340837
相關推薦
- 2022-12-13 Python?urllib?入門使用詳細教程_python
- 2022-10-12 深入淺出Golang中select的實現原理_Golang
- 2022-06-16 python遺傳算法之單/多目標規劃問題_python
- 2024-01-15 Stream流 - 獲取Stream和轉換操作(含基本數據類型流)
- 2022-02-19 Android~日志工具Log
- 2022-11-04 解析Android?Jetpack簡介_Android
- 2022-06-17 一文輕松了解ASP.NET與ASP.NET?Core多環境配置對比_實用技巧
- 2022-10-25 idea resources和webapp下面的文件不編譯怎么辦?
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支