#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ 摄像头地理位置配置工具 用于设置摄像头的经纬度坐标和朝向角度 """ import os import sys def update_config_file(lat, lng, heading, api_key=None): """更新配置文件中的摄像头位置信息""" config_path = "src/config.py" # 读取配置文件 with open(config_path, 'r', encoding='utf-8') as f: content = f.read() # 更新纬度 if "CAMERA_LATITUDE = " in content: lines = content.split('\n') for i, line in enumerate(lines): if line.startswith('CAMERA_LATITUDE = '): lines[i] = f'CAMERA_LATITUDE = {lat} # 摄像头纬度' break content = '\n'.join(lines) # 更新经度 if "CAMERA_LONGITUDE = " in content: lines = content.split('\n') for i, line in enumerate(lines): if line.startswith('CAMERA_LONGITUDE = '): lines[i] = f'CAMERA_LONGITUDE = {lng} # 摄像头经度' break content = '\n'.join(lines) # 更新朝向 if "CAMERA_HEADING = " in content: lines = content.split('\n') for i, line in enumerate(lines): if line.startswith('CAMERA_HEADING = '): lines[i] = f'CAMERA_HEADING = {heading} # 摄像头朝向角度' break content = '\n'.join(lines) # 更新API key(如果提供) if api_key and 'GAODE_API_KEY = ' in content: lines = content.split('\n') for i, line in enumerate(lines): if line.startswith('GAODE_API_KEY = '): lines[i] = f'GAODE_API_KEY = "{api_key}" # 高德地图API密钥' break content = '\n'.join(lines) # 写回配置文件 with open(config_path, 'w', encoding='utf-8') as f: f.write(content) def main(): print("=" * 60) print("🚁 无人机摄像头地理位置配置工具") print("=" * 60) print() print("📍 请设置摄像头的地理位置信息") print("提示: 可以通过高德地图等应用获取准确的经纬度坐标") print() try: # 获取纬度 lat = float(input("请输入摄像头纬度 (例: 39.9042): ")) if not (-90 <= lat <= 90): raise ValueError("纬度必须在-90到90之间") # 获取经度 lng = float(input("请输入摄像头经度 (例: 116.4074): ")) if not (-180 <= lng <= 180): raise ValueError("经度必须在-180到180之间") # 获取朝向 heading = float(input("请输入摄像头朝向角度 (0-360°, 0为正北): ")) if not (0 <= heading <= 360): raise ValueError("朝向角度必须在0到360之间") # 可选:设置高德API Key print("\n🔑 高德地图API Key设置 (可选)") print("如果您有高德开放平台的API Key,请输入以获得更好的地图体验") api_key = input("请输入高德API Key (留空跳过): ").strip() # 更新配置 update_config_file(lat, lng, heading, api_key if api_key else None) print("\n✅ 配置更新成功!") print(f"📍 摄像头位置: ({lat:.6f}, {lng:.6f})") print(f"🧭 朝向角度: {heading}°") if api_key: print("🔑 API Key 已设置") print("\n🎯 建议使用步骤:") print("1. 运行 python run.py 启动系统") print("2. 选择Web模式获得最佳体验") print("3. 按 'm' 键打开地图查看效果") print("4. 按 'c' 键校准距离参数以提高精度") except ValueError as e: print(f"❌ 输入错误: {e}") print("请重新运行程序并输入正确的数值") sys.exit(1) except Exception as e: print(f"❌ 配置失败: {e}") sys.exit(1) if __name__ == "__main__": main()