From 8a0d2588de416d34dcac214f5495b92e62e0fe7e Mon Sep 17 00:00:00 2001 From: yuanshi <1797230754@qq.com> Date: Tue, 20 Jun 2023 21:16:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=8E=B7=E5=8F=96=E6=B5=B7?= =?UTF-8?q?=E6=8B=94=E5=9D=A1=E5=BA=A6=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/FireDetect/main.py | 47 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/src/FireDetect/main.py b/src/FireDetect/main.py index 2440c97..b51f14e 100644 --- a/src/FireDetect/main.py +++ b/src/FireDetect/main.py @@ -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')