#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ 无人机战场态势感知系统 - Web版本 先显示地图界面,通过按钮控制摄像头启动和显示 """ import sys import os from src import WebServer, config def main(): """主函数""" global config # 声明 config 为全局变量 print("=" * 60) print("🚁 无人机战场态势感知系统 - Web版本") print("=" * 60) print() # 检查配置 print("📋 系统配置检查...") print(f"📍 摄像头位置: ({config.CAMERA_LATITUDE:.6f}, {config.CAMERA_LONGITUDE:.6f})") print(f"🧭 摄像头朝向: {config.CAMERA_HEADING}°") print(f"🔑 API Key: {'已配置' if config.GAODE_API_KEY != 'your_gaode_api_key_here' else '未配置'}") print() if config.GAODE_API_KEY == "your_gaode_api_key_here": print("⚠️ 警告: 未配置高德地图API Key") print(" 地图功能可能受限,建议运行 setup_camera_location.py 进行配置") print() # 检查是否为默认配置,提供自动配置选项 if (config.CAMERA_LATITUDE == 39.9042 and config.CAMERA_LONGITUDE == 116.4074 and config.CAMERA_HEADING == 0): print("🤖 检测到摄像头使用默认配置") print(" 是否要自动配置摄像头位置和朝向?") print(" • 输入 'y' - 立即自动配置") print(" • 输入 'n' - 跳过,使用Web界面配置") print(" • 直接回车 - 跳过自动配置") print() try: choice = input("🔧 请选择 (y/n/回车): ").strip().lower() if choice == 'y': print("\n🚀 启动自动配置...") from src.orientation_detector import OrientationDetector detector = OrientationDetector() result = detector.auto_configure_camera_location() if result['success']: print(f"✅ 自动配置成功!") print(f"📍 新位置: ({result['gps_location'][0]:.6f}, {result['gps_location'][1]:.6f})") print(f"🧭 新朝向: {result['camera_heading']:.1f}°") apply_choice = input("\n🔧 是否应用此配置? (y/n): ").strip().lower() if apply_choice == 'y': detector.update_camera_config( result['gps_location'], result['camera_heading'] ) print("✅ 配置已应用!") # 重新加载配置模块 import importlib import src.config importlib.reload(src.config) # 更新全局 config 变量 config = src.config else: print("⏭️ 配置未应用,将使用原配置") else: print("❌ 自动配置失败,将使用默认配置") print("💡 可以在Web界面启动后使用自动配置功能") print() elif choice == 'n': print("⏭️ 已跳过自动配置") print("💡 提示: 系统启动后可在Web界面使用自动配置功能") print() else: print("⏭️ 已跳过自动配置") print() except KeyboardInterrupt: print("\n⏭️ 已跳过自动配置") print() except Exception as e: print(f"⚠️ 自动配置过程出错: {e}") print("💡 将使用默认配置,可在Web界面手动配置") print() # 系统介绍 print("🎯 系统功能:") print(" • 🗺️ 实时地图显示") print(" • 📷 摄像头控制(Web界面)") print(" • 👥 人员检测和定位") print(" • 📏 距离测量") print(" • 🌐 Web界面操作") print() print("💡 使用说明:") print(" 1. 系统启动后会自动打开浏览器") print(" 2. 在地图界面点击 '启动视频侦察' 按钮") print(" 3. 右上角会显示摄像头小窗口") print(" 4. 检测到的人员会在地图上用红点标记") print(" 5. 点击 '停止侦察' 按钮停止检测") print() try: # 创建并启动Web服务器 print("🌐 正在启动Web服务器...") web_server = WebServer() # 获取本机IP地址用于移动设备连接 import socket try: # 连接到一个远程地址来获取本机IP s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.connect(("8.8.8.8", 80)) local_ip = s.getsockname()[0] s.close() except: local_ip = "127.0.0.1" # 启动服务器 print("✅ 系统已启动!") print(f"🔒 本地访问: https://127.0.0.1:5000") print(f"🔒 手机/平板访问: https://{local_ip}:5000") print(f"📱 手机客户端: https://{local_ip}:5000/mobile/mobile_client.html") print(f"🚁 无人机控制: https://127.0.0.1:5000/drone_control.html") print("🔴 按 Ctrl+C 停止服务器") print() print("🔑 HTTPS注意事项:") print(" • 首次访问会显示'您的连接不是私密连接'警告") print(" • 点击'高级'->'继续访问localhost(不安全)'即可") print(" • 手机访问时也需要点击'继续访问'") print() # 尝试自动打开浏览器 try: import webbrowser webbrowser.open('https://127.0.0.1:5000') print("🌐 浏览器已自动打开") except: print("⚠️ 无法自动打开浏览器,请手动访问地址") print("-" * 60) # 运行服务器,绑定到所有网络接口,启用HTTPS web_server.run(host='0.0.0.0', port=5000, debug=False, ssl_enabled=True) except KeyboardInterrupt: print("\n🔴 用户中断程序") except Exception as e: print(f"❌ 程序运行出错: {e}") print("💡 建议检查:") print(" 1. 是否正确安装了所有依赖包") print(" 2. 摄像头是否正常工作") print(" 3. 网络连接是否正常") sys.exit(1) finally: print("👋 程序已结束") if __name__ == "__main__": main()