diff --git a/src/autonomus_drone_hand_gesture_project/drone_controller.py b/src/autonomus_drone_hand_gesture_project/drone_controller.py index 2f1edeadb0..4e121b9b29 100644 --- a/src/autonomus_drone_hand_gesture_project/drone_controller.py +++ b/src/autonomus_drone_hand_gesture_project/drone_controller.py @@ -5,6 +5,8 @@ """ import time +import threading +import math class SimpleDroneController: @@ -27,13 +29,23 @@ def __init__(self, airsim_module, speech_manager=None, config=None): # 控制状态 self.last_control_time = 0 self.last_gesture = None + self.flight_mode = "manual" # manual, auto, circle, eight, square, return_home + + # 飞行任务状态 + self.auto_flying = False + self.auto_flight_thread = None + self.stop_auto_flight = False + + # 飞行高度控制 + self.target_altitude = self.altitude + self.altitude_change_step = 2.0 # 米 # 上次语音提示状态 self.last_connection_announced = False self.last_takeoff_announced = False self.last_land_announced = False - print("✓ 简单的无人机控制器已初始化") + print("✓ 增强的无人机控制器已初始化") def connect(self): """连接AirSim无人机""" @@ -130,9 +142,11 @@ def takeoff(self): time.sleep(1) # 上升到指定高度 + self.target_altitude = self.altitude self.client.moveToZAsync(self.altitude, 3).join() self.flying = True + self.flight_mode = "manual" print("✅ 无人机成功起飞") # 语音提示:起飞成功 @@ -156,6 +170,9 @@ def land(self): if not self.connected: return False + # 停止自动飞行任务 + self.stop_auto_flight_task() + # 语音提示:正在降落 if (self.speech_manager and self.speech_manager.enabled and @@ -168,6 +185,7 @@ def land(self): if self.airsim is None or self.client is None: print("✅ 模拟降落") self.flying = False + self.flight_mode = "manual" # 语音提示:降落成功 if (self.speech_manager and @@ -179,6 +197,7 @@ def land(self): print("降落中...") self.client.landAsync().join() self.flying = False + self.flight_mode = "manual" print("✅ 无人机已降落") # 语音提示:降落成功 @@ -191,6 +210,385 @@ def land(self): print(f"降落失败: {e}") return False + def hover(self): + """悬停""" + if not self.connected or not self.flying: + return False + + try: + if self.airsim is None or self.client is None: + print("模拟悬停") + self.flight_mode = "manual" + return True + + self.client.hoverAsync().join() + self.flight_mode = "manual" + print("✅ 无人机悬停") + + # 语音提示:悬停 + if (self.speech_manager and + self.speech_manager.enabled): + self.speech_manager.speak('hovering') + + return True + except Exception as e: + print(f"悬停失败: {e}") + return False + + def return_home(self): + """返航到起飞点""" + if not self.connected or not self.flying: + return False + + # 停止当前自动飞行任务 + self.stop_auto_flight_task() + + # 语音提示:返航 + if (self.speech_manager and + self.speech_manager.enabled): + self.speech_manager.speak('returning_home') + + try: + if self.airsim is None or self.client is None: + print("✅ 模拟返航") + self.flight_mode = "return_home" + return True + + print("返航中...") + self.flight_mode = "return_home" + + # 返回到起点 (0, 0, altitude) + self.client.moveToPositionAsync(0, 0, self.target_altitude, 5).join() + + # 悬停 + self.client.hoverAsync().join() + self.flight_mode = "manual" + print("✅ 返航完成") + + # 语音提示:返航成功 + if (self.speech_manager and + self.speech_manager.enabled): + self.speech_manager.speak('return_home_success') + + return True + except Exception as e: + print(f"❌ 返航失败: {e}") + return False + + def start_auto_flight(self): + """启动自动飞行模式(正方形轨迹)""" + if not self.connected or not self.flying: + return False + + # 停止之前的自动飞行任务 + self.stop_auto_flight_task() + + # 语音提示:自动飞行 + if (self.speech_manager and + self.speech_manager.enabled): + self.speech_manager.speak('auto_flight_start') + + try: + if self.airsim is None or self.client is None: + print("✅ 模拟自动飞行") + self.flight_mode = "auto" + return True + + # 启动自动飞行线程 + self.stop_auto_flight = False + self.auto_flight_thread = threading.Thread(target=self._square_flight_task) + self.auto_flight_thread.daemon = True + self.auto_flight_thread.start() + + self.flight_mode = "auto" + print("✅ 自动飞行模式启动") + + return True + except Exception as e: + print(f"❌ 启动自动飞行失败: {e}") + return False + + def _square_flight_task(self): + """正方形飞行任务""" + if self.airsim is None or self.client is None: + return + + try: + side_length = 10.0 # 正方形边长(米) + speed = 3.0 # 飞行速度 + + # 四个顶点 + points = [ + (side_length/2, side_length/2, self.target_altitude), + (side_length/2, -side_length/2, self.target_altitude), + (-side_length/2, -side_length/2, self.target_altitude), + (-side_length/2, side_length/2, self.target_altitude), + (0, 0, self.target_altitude) # 返回起点 + ] + + for i, point in enumerate(points): + if self.stop_auto_flight: + break + + print(f"自动飞行: 前往点 {i+1}/{len(points)}: {point}") + self.client.moveToPositionAsync(point[0], point[1], point[2], speed).join() + + # 在每个顶点悬停1秒 + if not self.stop_auto_flight: + time.sleep(1) + + if not self.stop_auto_flight: + # 悬停 + self.client.hoverAsync().join() + self.flight_mode = "manual" + print("✅ 自动飞行完成") + + # 语音提示 + if (self.speech_manager and + self.speech_manager.enabled): + self.speech_manager.speak('auto_flight_complete') + except Exception as e: + print(f"自动飞行任务错误: {e}") + + def start_circle_flight(self): + """启动圆形盘旋飞行""" + if not self.connected or not self.flying: + return False + + # 停止之前的自动飞行任务 + self.stop_auto_flight_task() + + # 语音提示:圆形盘旋 + if (self.speech_manager and + self.speech_manager.enabled): + self.speech_manager.speak('circle_flight_start') + + try: + if self.airsim is None or self.client is None: + print("✅ 模拟圆形盘旋") + self.flight_mode = "circle" + return True + + # 启动圆形飞行线程 + self.stop_auto_flight = False + self.auto_flight_thread = threading.Thread(target=self._circle_flight_task) + self.auto_flight_thread.daemon = True + self.auto_flight_thread.start() + + self.flight_mode = "circle" + print("✅ 圆形盘旋模式启动") + + return True + except Exception as e: + print(f"❌ 启动圆形盘旋失败: {e}") + return False + + def _circle_flight_task(self): + """圆形飞行任务""" + if self.airsim is None or self.client is None: + return + + try: + radius = 5.0 # 圆半径(米) + duration = 30.0 # 飞行时间(秒) + start_time = time.time() + + while time.time() - start_time < duration and not self.stop_auto_flight: + # 计算圆上的点 + t = time.time() - start_time + angle = t * 2 * math.pi / 5 # 每5秒一圈 + + x = radius * math.cos(angle) + y = radius * math.sin(angle) + + # 飞向圆上的点 + self.client.moveToPositionAsync(x, y, self.target_altitude, 2).join() + + # 短暂延迟 + time.sleep(0.1) + + if not self.stop_auto_flight: + # 返回中心并悬停 + self.client.moveToPositionAsync(0, 0, self.target_altitude, 3).join() + self.client.hoverAsync().join() + self.flight_mode = "manual" + print("✅ 圆形盘旋完成") + + # 语音提示 + if (self.speech_manager and + self.speech_manager.enabled): + self.speech_manager.speak('circle_flight_complete') + except Exception as e: + print(f"圆形飞行任务错误: {e}") + + def start_eight_flight(self): + """启动8字形飞行""" + if not self.connected or not self.flying: + return False + + # 停止之前的自动飞行任务 + self.stop_auto_flight_task() + + # 语音提示:8字形飞行 + if (self.speech_manager and + self.speech_manager.enabled): + self.speech_manager.speak('eight_flight_start') + + try: + if self.airsim is None or self.client is None: + print("✅ 模拟8字形飞行") + self.flight_mode = "eight" + return True + + # 启动8字形飞行线程 + self.stop_auto_flight = False + self.auto_flight_thread = threading.Thread(target=self._eight_flight_task) + self.auto_flight_thread.daemon = True + self.auto_flight_thread.start() + + self.flight_mode = "eight" + print("✅ 8字形飞行模式启动") + + return True + except Exception as e: + print(f"❌ 启动8字形飞行失败: {e}") + return False + + def _eight_flight_task(self): + """8字形飞行任务""" + if self.airsim is None or self.client is None: + return + + try: + radius = 5.0 # 半径(米) + duration = 40.0 # 飞行时间(秒) + start_time = time.time() + + while time.time() - start_time < duration and not self.stop_auto_flight: + # 计算8字形参数方程 + t = time.time() - start_time + scale = t * 2 * math.pi / 10 # 每10秒一个完整8字 + + # 8字形参数方程 + x = radius * math.sin(scale) + y = radius * math.sin(scale) * math.cos(scale) + + # 飞向8字形上的点 + self.client.moveToPositionAsync(x, y, self.target_altitude, 2).join() + + # 短暂延迟 + time.sleep(0.1) + + if not self.stop_auto_flight: + # 返回中心并悬停 + self.client.moveToPositionAsync(0, 0, self.target_altitude, 3).join() + self.client.hoverAsync().join() + self.flight_mode = "manual" + print("✅ 8字形飞行完成") + + # 语音提示 + if (self.speech_manager and + self.speech_manager.enabled): + self.speech_manager.speak('eight_flight_complete') + except Exception as e: + print(f"8字形飞行任务错误: {e}") + + def increase_altitude(self): + """增加飞行高度""" + if not self.connected or not self.flying: + return False + + try: + self.target_altitude -= self.altitude_change_step # AirSim中Z轴向下为负 + + # 语音提示:增加高度 + if (self.speech_manager and + self.speech_manager.enabled): + self.speech_manager.speak('altitude_increasing') + + if self.airsim is None or self.client is None: + print(f"✅ 模拟增加高度到: {-self.target_altitude:.1f}米") + return True + + print(f"增加高度到: {-self.target_altitude:.1f}米") + self.client.moveToZAsync(self.target_altitude, 3).join() + print("✅ 高度调整完成") + + return True + except Exception as e: + print(f"❌ 调整高度失败: {e}") + return False + + def decrease_altitude(self): + """降低飞行高度""" + if not self.connected or not self.flying: + return False + + try: + self.target_altitude += self.altitude_change_step # AirSim中Z轴向下为负 + + # 确保高度不低于最小值 + min_altitude = -20.0 + if self.target_altitude > min_altitude: + self.target_altitude = min_altitude + + # 语音提示:降低高度 + if (self.speech_manager and + self.speech_manager.enabled): + self.speech_manager.speak('altitude_decreasing') + + if self.airsim is None or self.client is None: + print(f"✅ 模拟降低高度到: {-self.target_altitude:.1f}米") + return True + + print(f"降低高度到: {-self.target_altitude:.1f}米") + self.client.moveToZAsync(self.target_altitude, 3).join() + print("✅ 高度调整完成") + + return True + except Exception as e: + print(f"❌ 调整高度失败: {e}") + return False + + def set_altitude(self, altitude=None): + """设置特定飞行高度""" + if not self.connected or not self.flying: + return False + + try: + if altitude is None: + # 使用默认高度 + altitude = self.altitude + + self.target_altitude = altitude + + # 语音提示:设置高度 + if (self.speech_manager and + self.speech_manager.enabled): + self.speech_manager.speak_direct(f"设置高度到{-altitude:.1f}米") + + if self.airsim is None or self.client is None: + print(f"✅ 模拟设置高度到: {-altitude:.1f}米") + return True + + print(f"设置高度到: {-altitude:.1f}米") + self.client.moveToZAsync(altitude, 3).join() + print("✅ 高度设置完成") + + return True + except Exception as e: + print(f"❌ 设置高度失败: {e}") + return False + + def stop_auto_flight_task(self): + """停止自动飞行任务""" + if self.auto_flight_thread and self.auto_flight_thread.is_alive(): + self.stop_auto_flight = True + self.auto_flight_thread.join(timeout=2.0) + self.auto_flight_thread = None + self.flight_mode = "manual" + print("✅ 自动飞行任务已停止") + def move_by_gesture(self, gesture, confidence): """根据手势移动""" if not self.connected or not self.flying: @@ -235,9 +633,13 @@ def move_by_gesture(self, gesture, confidence): elif gesture == "Forward": self.client.moveByVelocityAsync(0, -self.velocity, 0, self.duration) success = True + elif gesture == "Backward": + self.client.moveByVelocityAsync(0, self.velocity, 0, self.duration) + success = True elif gesture == "Stop": self.client.hoverAsync() success = True + self.flight_mode = "manual" # 悬停语音提示 if (self.speech_manager and self.speech_manager.enabled): @@ -245,9 +647,26 @@ def move_by_gesture(self, gesture, confidence): elif gesture == "Hover": self.client.hoverAsync() success = True + self.flight_mode = "manual" if (self.speech_manager and self.speech_manager.enabled): self.speech_manager.speak('hovering') + elif gesture == "ReturnHome": + success = self.return_home() + elif gesture == "AutoFlight": + success = self.start_auto_flight() + elif gesture == "CircleFlight": + success = self.start_circle_flight() + elif gesture == "EightFlight": + success = self.start_eight_flight() + elif gesture == "SquareFlight": + success = self.start_auto_flight() # 复用自动飞行 + elif gesture == "IncreaseAltitude": + success = self.increase_altitude() + elif gesture == "DecreaseAltitude": + success = self.decrease_altitude() + elif gesture == "SetAltitude": + success = self.set_altitude() elif gesture == "Grab": # 抓取动作(模拟) print("执行抓取动作") @@ -283,21 +702,6 @@ def move_by_gesture(self, gesture, confidence): if (self.speech_manager and self.speech_manager.enabled): self.speech_manager.speak('gesture_photo') - elif gesture == "ReturnHome": - # 返航 - print("执行返航") - self.client.moveToPositionAsync(0, 0, self.altitude, 5) - success = True - if (self.speech_manager and - self.speech_manager.enabled): - self.speech_manager.speak('gesture_return_home') - elif gesture == "AutoFlight": - # 自动飞行模式 - print("启动自动飞行模式") - success = True - if (self.speech_manager and - self.speech_manager.enabled): - self.speech_manager.speak('gesture_auto_flight') if success: self.last_control_time = current_time @@ -312,6 +716,9 @@ def emergency_stop(self): """紧急停止""" if self.connected: try: + # 停止自动飞行任务 + self.stop_auto_flight_task() + if self.flying and self.client is not None: print("紧急降落...") @@ -329,4 +736,9 @@ def emergency_stop(self): pass self.connected = False - self.flying = False \ No newline at end of file + self.flying = False + self.flight_mode = "manual" + + def get_flight_mode(self): + """获取当前飞行模式""" + return self.flight_mode \ No newline at end of file diff --git a/src/autonomus_drone_hand_gesture_project/gesture_config.json b/src/autonomus_drone_hand_gesture_project/gesture_config.json index 0a14cccb19..7286a11db4 100644 --- a/src/autonomus_drone_hand_gesture_project/gesture_config.json +++ b/src/autonomus_drone_hand_gesture_project/gesture_config.json @@ -20,9 +20,9 @@ "skin_lower_h": 0, "skin_upper_h": 180, "skin_lower_s": 0, - "skin_upper_s": 127, - "skin_lower_v": 22, - "skin_upper_v": 178, + "skin_upper_s": 165, + "skin_lower_v": 16, + "skin_upper_v": 255, "min_hand_area": 3000, "max_hand_area": 30000, "hand_ratio_threshold": 1.5, @@ -104,14 +104,15 @@ "show_trajectory_heatmap": false, "theme": "dark", "trajectory_max_points": 100, - "ui_opacity": 0.7 + "ui_opacity": 0.7, + "show_flight_mode": true }, "performance": { "target_fps": 30, "resize_factor": 1.0, "enable_multiprocessing": false, - "mode": "accurate", - "current_mode_index": 2, + "mode": "balanced", + "current_mode_index": 1, "modes": [ "fast", "balanced", diff --git a/src/autonomus_drone_hand_gesture_project/main.py b/src/autonomus_drone_hand_gesture_project/main.py index a04228c60f..0c193452d7 100644 --- a/src/autonomus_drone_hand_gesture_project/main.py +++ b/src/autonomus_drone_hand_gesture_project/main.py @@ -165,6 +165,7 @@ def print_welcome_message(cap, speech_manager, libs): print(f" 语音反馈: {'已启用' if speech_manager.enabled else '已禁用'}") print(f" 性能监控: 已启用") print(f" 轨迹记录: 支持录制/回放功能") + print(f" 高级飞行模式: 方形轨迹、圆形盘旋、8字形飞行") print(f" AirSim: {'可用' if libs['airsim'] else '模拟模式'}") print("=" * 80) @@ -190,7 +191,9 @@ def print_instructions(): print("6. 轨迹记录功能:") print(" [1]开始录制 [2]停止录制 [3]保存轨迹 [4]回放轨迹 [5]清除轨迹 [6]暂停/继续") print("7. 键盘控制:") - print(" [W]向上 [S]向下 [A]向左 [D]向右 [F]向前 [X]停止 [H]悬停 [G]返航") + print(" [W]向上 [S]向下 [A]向左 [D]向右 [F]向前 [B]向后 [X]停止 [H]悬停") + print(" [G]返航 [Q]自动飞行模式 [E]圆形盘旋 [8]8字形飞行 [9]方形轨迹") + print(" [T]增加高度 [Y]降低高度 [U]设定高度") print("8. 调试功能:") print(" [H]切换帮助显示 [R]重置手势识别 [T]切换显示模式 [D]调试信息") print("9. 语音控制:") @@ -268,13 +271,20 @@ def main(): ord('a'): "Left", ord('A'): "Left", ord('d'): "Right", ord('D'): "Right", ord('f'): "Forward", ord('F'): "Forward", + ord('b'): "Backward", ord('B'): "Backward", ord('x'): "Stop", ord('X'): "Stop", ord('h'): "Hover", ord('H'): "Hover", ord('g'): "ReturnHome", ord('G'): "ReturnHome", - ord('b'): "AutoFlight", ord('B'): "AutoFlight", + ord('q'): "AutoFlight", ord('Q'): "AutoFlight", ord('p'): "TakePhoto", ord('P'): "TakePhoto", ord('r'): "RotateCW", ord('R'): "RotateCW", ord('l'): "RotateCCW", ord('L'): "RotateCCW", + ord('e'): "CircleFlight", ord('E'): "CircleFlight", + ord('8'): "EightFlight", ord('*'): "EightFlight", + ord('9'): "SquareFlight", ord('('): "SquareFlight", + ord('t'): "IncreaseAltitude", ord('T'): "IncreaseAltitude", + ord('y'): "DecreaseAltitude", ord('Y'): "DecreaseAltitude", + ord('u'): "SetAltitude", ord('U'): "SetAltitude", } # 显示模式 @@ -335,6 +345,7 @@ def main(): config.set('display', 'show_performance_stats', value=True) config.set('display', 'show_system_resources', value=True) config.set('display', 'show_advanced_gestures', value=True) + config.set('display', 'show_flight_mode', value=True) config.set('display', 'show_debug_info', value=False) elif display_modes[current_display_mode] == 'detailed': config.set('display', 'show_contours', value=True) @@ -350,6 +361,7 @@ def main(): config.set('display', 'show_performance_stats', value=True) config.set('display', 'show_system_resources', value=True) config.set('display', 'show_advanced_gestures', value=True) + config.set('display', 'show_flight_mode', value=True) config.set('display', 'show_debug_info', value=True) elif display_modes[current_display_mode] == 'minimal': config.set('display', 'show_contours', value=False) @@ -363,6 +375,7 @@ def main(): config.set('display', 'show_performance_stats', value=True) config.set('display', 'show_system_resources', value=True) config.set('display', 'show_advanced_gestures', value=False) + config.set('display', 'show_flight_mode', value=True) config.set('display', 'show_debug_info', value=False) # 绘制轨迹(如果启用) @@ -380,6 +393,10 @@ def main(): trajectory_recorder, gesture_recognizer, performance_analyzer ) + # 绘制飞行模式信息 + if config.get('display', 'show_flight_mode'): + frame = ui_renderer.draw_flight_mode(frame, drone_controller) + # 绘制性能图表(如果启用详细模式) if display_modes[current_display_mode] == 'detailed': frame = ui_renderer.draw_performance_chart(frame, performance_analyzer) diff --git a/src/autonomus_drone_hand_gesture_project/speech_manager.py b/src/autonomus_drone_hand_gesture_project/speech_manager.py index 67f5f740c1..c9a585f5c4 100644 --- a/src/autonomus_drone_hand_gesture_project/speech_manager.py +++ b/src/autonomus_drone_hand_gesture_project/speech_manager.py @@ -52,6 +52,18 @@ def __init__(self, speech_lib, config=None): 'emergency_stop': "紧急停止,无人机已降落", 'hovering': "无人机悬停中", + # 高级飞行模式 + 'returning_home': "正在返航", + 'return_home_success': "返航成功", + 'auto_flight_start': "开始自动飞行模式", + 'auto_flight_complete': "自动飞行完成", + 'circle_flight_start': "开始圆形盘旋", + 'circle_flight_complete': "圆形盘旋完成", + 'eight_flight_start': "开始8字形飞行", + 'eight_flight_complete': "8字形飞行完成", + 'altitude_increasing': "正在增加高度", + 'altitude_decreasing': "正在降低高度", + # 手势相关 'gesture_detected': "手势识别就绪,请开始手势", 'gesture_start': "开始识别手势", @@ -77,6 +89,12 @@ def __init__(self, speech_lib, config=None): 'gesture_photo': "拍照", # 新增 'gesture_auto_flight': "自动飞行模式", # 新增 'gesture_return_home': "返航", # 新增 + 'gesture_circle_flight': "圆形盘旋", # 新增 + 'gesture_eight_flight': "8字形飞行", # 新增 + 'gesture_square_flight': "方形轨迹", # 新增 + 'gesture_increase_altitude': "增加高度", # 新增 + 'gesture_decrease_altitude': "降低高度", # 新增 + 'gesture_set_altitude': "设置高度", # 新增 # 系统相关 'program_start': "手势控制无人机系统已启动", diff --git a/src/autonomus_drone_hand_gesture_project/ui_renderer.py b/src/autonomus_drone_hand_gesture_project/ui_renderer.py index 048366bc4c..cb52a20513 100644 --- a/src/autonomus_drone_hand_gesture_project/ui_renderer.py +++ b/src/autonomus_drone_hand_gesture_project/ui_renderer.py @@ -52,6 +52,13 @@ def __init__(self, speech_manager=None, config=None): 'gesture_photo': (255, 165, 0), 'gesture_return_home': (0, 128, 128), 'gesture_auto_flight': (128, 0, 128), + # 飞行模式颜色 + 'flight_mode_manual': (0, 255, 0), + 'flight_mode_auto': (255, 165, 0), + 'flight_mode_circle': (0, 255, 255), + 'flight_mode_eight': (255, 0, 255), + 'flight_mode_square': (255, 255, 0), + 'flight_mode_return_home': (0, 128, 128), } print("✓ 中文UI渲染器已初始化") @@ -116,7 +123,7 @@ def draw_status_bar(self, frame, drone_controller, gesture, confidence, fps, pro frame = cv2.addWeighted(overlay, 0.7, frame, 0.3, 0) # 标题 - title = "手势控制无人机系统 - 性能统计版" + title = "手势控制无人机系统 - 高级飞行模式版" frame = self.draw_text(frame, title, (10, 10), size=20, color=self.colors['title']) # 连接状态 @@ -254,6 +261,48 @@ def draw_status_bar(self, frame, drone_controller, gesture, confidence, fps, pro return frame + def draw_flight_mode(self, frame, drone_controller): + """绘制飞行模式信息""" + if not drone_controller.connected: + return frame + + h, w = frame.shape[:2] + + # 飞行模式显示 + flight_mode = drone_controller.get_flight_mode() + + # 根据飞行模式选择颜色和文本 + mode_texts = { + 'manual': ('手动模式', self.colors['flight_mode_manual']), + 'auto': ('自动飞行', self.colors['flight_mode_auto']), + 'circle': ('圆形盘旋', self.colors['flight_mode_circle']), + 'eight': ('8字形飞行', self.colors['flight_mode_eight']), + 'square': ('方形轨迹', self.colors['flight_mode_square']), + 'return_home': ('返航中', self.colors['flight_mode_return_home']) + } + + if flight_mode in mode_texts: + text, color = mode_texts[flight_mode] + mode_text = f"飞行模式: {text}" + + # 绘制背景 + text_size = cv2.getTextSize(mode_text, cv2.FONT_HERSHEY_SIMPLEX, 0.7, 2)[0] + bg_x = w - text_size[0] - 20 + bg_y = 150 + bg_w = text_size[0] + 10 + bg_h = text_size[1] + 10 + + # 绘制半透明背景 + overlay = frame.copy() + cv2.rectangle(overlay, (bg_x, bg_y), (bg_x + bg_w, bg_y + bg_h), (0, 0, 0), -1) + frame = cv2.addWeighted(overlay, 0.7, frame, 0.3, 0) + + # 绘制文本 + frame = self.draw_text(frame, mode_text, (bg_x + 5, bg_y + 5), + size=14, color=color) + + return frame + def draw_help_bar(self, frame): """绘制帮助栏""" if not self.config.get('display', 'show_help'): @@ -262,19 +311,20 @@ def draw_help_bar(self, frame): h, w = frame.shape[:2] # 绘制底部帮助栏 - cv2.rectangle(frame, (0, h - 120), (w, h), (0, 0, 0), -1) + cv2.rectangle(frame, (0, h - 140), (w, h), (0, 0, 0), -1) # 帮助文本 help_lines = [ - "C:连接 空格:起飞/降落 ESC:退出 W/A/S/D/F/X:键盘控制", + "C:连接 空格:起飞/降落 ESC:退出 W/A/S/D/F/B:键盘控制", "H:切换帮助 R:重置识别 T:切换显示模式 D:调试信息", "V:切换语音反馈 M:测试语音 P:性能报告 L:性能快照 K:导出日志", - "O:切换性能模式 P:详细报告 R:重置统计", + "O:切换性能模式 Q:自动飞行 E:圆形盘旋 8:8字形 9:方形轨迹", + "T/Y/U:高度控制 G:返航 X:停止 H:悬停", "1:开始录制 2:停止录制 3:保存轨迹 4:回放轨迹 5:清除轨迹 6:暂停/继续" ] for i, line in enumerate(help_lines): - y_pos = h - 105 + i * 20 + y_pos = h - 125 + i * 20 frame = self.draw_text(frame, line, (10, y_pos), size=14, color=self.colors['help']) return frame