#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ 摄像头自动配置工具 自动获取设备位置和朝向,设置摄像头参数 """ import sys import os sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from src.orientation_detector import OrientationDetector def main(): """主函数""" print("=" * 60) print("🤖 摄像头自动配置工具") print("=" * 60) print() print("🎯 功能说明:") print(" • 自动获取当前设备的GPS位置") print(" • 自动检测设备朝向") print(" • 计算摄像头应该面向用户的角度") print(" • 自动更新系统配置文件") print() print("⚠️ 注意事项:") print(" • 请确保设备连接到互联网") print(" • Windows系统可能需要开启位置服务") print(" • 桌面设备朝向检测精度有限") print() try: # 创建朝向检测器 detector = OrientationDetector() # 执行自动配置 result = detector.auto_configure_camera_location() if result['success']: print() print("✅ 自动配置成功!") print("📊 配置详情:") print(f" 📍 GPS位置: {result['gps_location'][0]:.6f}, {result['gps_location'][1]:.6f}") print(f" 🧭 设备朝向: {result['device_heading']:.1f}°") print(f" 📷 摄像头朝向: {result['camera_heading']:.1f}°") print(f" 🎯 定位方法: {result['method']}") print(f" 📏 定位精度: ±{result['accuracy']:.0f}m") print() # 询问是否应用配置 while True: choice = input("🔧 是否应用此配置? (y/n/r): ").strip().lower() if choice == 'y': # 应用配置 detector.update_camera_config( result['gps_location'], result['camera_heading'] ) print("✅ 配置已应用到系统!") break elif choice == 'n': print("⏭️ 配置未应用") break elif choice == 'r': # 重新检测 print("\n🔄 重新检测...") result = detector.auto_configure_camera_location() if not result['success']: print("❌ 重新检测失败") break print("📊 新的配置详情:") print(f" 📍 GPS位置: {result['gps_location'][0]:.6f}, {result['gps_location'][1]:.6f}") print(f" 🧭 设备朝向: {result['device_heading']:.1f}°") print(f" 📷 摄像头朝向: {result['camera_heading']:.1f}°") print(f" 🎯 定位方法: {result['method']}") print(f" 📏 定位精度: ±{result['accuracy']:.0f}m") print() else: print("❌ 请输入 y(应用)/n(取消)/r(重新检测)") else: print("❌ 自动配置失败") print("💡 建议:") print(" 1. 检查网络连接") print(" 2. 使用手动配置: python tools/setup_camera_location.py") print(" 3. 或在Web界面中手动设置") except KeyboardInterrupt: print("\n🔴 用户取消操作") except Exception as e: print(f"❌ 配置过程出错: {e}") print("💡 建议使用手动配置工具") finally: print("\n👋 配置工具结束") def test_gps_only(): """仅测试GPS定位功能""" print("🧪 GPS定位测试") print("-" * 30) detector = OrientationDetector() location = detector.get_current_gps_location() if location: lat, lng, accuracy = location print(f"✅ GPS测试成功:") print(f" 📍 位置: {lat:.6f}, {lng:.6f}") print(f" 📏 精度: ±{accuracy:.0f}m") else: print("❌ GPS测试失败") def test_heading_only(): """仅测试朝向检测功能""" print("🧪 朝向检测测试") print("-" * 30) detector = OrientationDetector() heading = detector.get_device_heading() if heading is not None: print(f"✅ 朝向测试成功:") print(f" 🧭 设备朝向: {heading:.1f}°") # 计算摄像头朝向 camera_heading = detector.calculate_camera_heading_facing_user(heading) print(f" 📷 摄像头朝向: {camera_heading:.1f}°") else: print("❌ 朝向测试失败") if __name__ == "__main__": import argparse parser = argparse.ArgumentParser(description='摄像头自动配置工具') parser.add_argument('--test-gps', action='store_true', help='仅测试GPS功能') parser.add_argument('--test-heading', action='store_true', help='仅测试朝向功能') args = parser.parse_args() if args.test_gps: test_gps_only() elif args.test_heading: test_heading_only() else: main()