增加获取海拔坡度功能

yangshi_branch
yuanshi 2 years ago
parent ed239f3912
commit 8a0d2588de

@ -20,10 +20,14 @@ import os
import nvidia_smi
from ctypes import windll
import math
import platform
import curses
from termcolor import colored, cprint
import requests
import platform
if platform.system() == 'Windows':
import windows_curses as curses
else:
import curses
FILE = Path(__file__).resolve()
ROOT = FILE.parents[0] # YOLOv5 root directory
@ -508,6 +512,31 @@ def check_data(arr):
except TypeError: # 不可迭代的情况
return False
#获取高程坡度
def get_elevation_slope(lat, lng):
"""
获取经纬度对应地点的海拔高度和坡度
:param lat: 纬度
:param lng: 经度
:return: 包含海拔高度和坡度信息的字典
"""
url = 'https://portal.opentopography.org/API/globaldem?demtype=SRTMGL1&west={}&south={}&east={}&north={}&outputFormat=JSON'.format(
lng - 0.001, lat - 0.001, lng + 0.001, lat + 0.001)
response = requests.get(url)
if response.status_code == 200:
json_data = response.json()
if 'elevation' in json_data and 'slope' in json_data:
elevation = json_data['elevation']
slope = json_data['slope']
return {'elevation': elevation, 'slope': slope}
else:
print('获取高度信息失败:{}'.format(json_data))
else:
print('请求失败HTTP错误{}'.format(response.status_code))
return None
def main():
# cap = cv2.VideoCapture("http://admin:admin@192.168.8.126:8081")
# print("图像加载成功")
@ -532,6 +561,16 @@ def main():
Fire_centY = target[0][1]
Fire_W = target[0][2]
Fire_H = target[0][3]
lat = 37.7749
lng = -122.4194
result = get_elevation_slope(lat, lng)
if result:
elevation = result['elevation']
slope = result['slope']
else:
elevation = 200
slope = 12
# print(img_b64)
data = {
"img": img_b64,
@ -540,7 +579,9 @@ def main():
"cent_x": Fire_centX,
"cent_y": Fire_centY,
"length": Fire_W,
"width": Fire_H
"width": Fire_H,
"elevation": elevation,
"slope": slope
}
json_data = json.dumps(data).encode('utf-8')

Loading…
Cancel
Save