Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
beae83d
尝试修改冲突,提交
rhcgg Dec 18, 2025
bbe755b
perceptive_drone_explorer.py
rhcgg Dec 18, 2025
67357c2
Merge branch 'OpenHUTB:main' into main
rhcgg Dec 18, 2025
7ceb6bf
Remove unnecessary comment lines
rhcgg Dec 18, 2025
9daf9aa
删除,不必要修改
rhcgg Dec 18, 2025
d5d4c2f
Merge branch 'main' of https://github.com/rhcgg/Neural-network
rhcgg Dec 18, 2025
dbb6a67
Merge branch 'OpenHUTB:main' into main
rhcgg Dec 18, 2025
6d4f124
perceptive_drone_explorer.py
rhcgg Dec 18, 2025
39f70bc
Merge branch 'main' of https://github.com/rhcgg/Neural-network
rhcgg Dec 18, 2025
0e87997
Merge branch 'OpenHUTB:main' into main
rhcgg Dec 19, 2025
5df39f3
Merge branch 'OpenHUTB:main' into main
rhcgg Dec 19, 2025
3ee6b08
Merge branch 'OpenHUTB:main' into main
rhcgg Dec 19, 2025
76c312d
进一步完善化码使其健壮与工程化
rhcgg Dec 19, 2025
b352e2f
Merge branch 'OpenHUTB:main' into main
rhcgg Dec 19, 2025
51ff05e
添加了一个手动控制,通过前视窗口控制
rhcgg Dec 19, 2025
40ce3fc
Merge branch 'main' of https://github.com/rhcgg/Neural-network
rhcgg Dec 19, 2025
4ed272f
Merge branch 'main' of https://github.com/rhcgg/Neural-network
rhcgg Dec 19, 2025
98557f8
添加了一个手动控制,通过前视窗口控制
rhcgg Dec 19, 2025
e691edd
Merge branch 'OpenHUTB:main' into main
rhcgg Dec 20, 2025
175c234
智能决策算法增强
rhcgg Dec 20, 2025
5fad2f1
Merge branch 'OpenHUTB:main' into main
rhcgg Dec 20, 2025
6c3ca6b
Merge branch 'OpenHUTB:main' into main
rhcgg Dec 21, 2025
9318dd1
性能监控与数据闭环
rhcgg Dec 21, 2025
c8e8889
Merge branch 'OpenHUTB:main' into main
rhcgg Dec 21, 2025
c7df8a4
功能完善
rhcgg Dec 21, 2025
169d67c
功能进一步完善
rhcgg Dec 22, 2025
c3adfbc
Merge branch 'main' of https://github.com/rhcgg/Neural-network
rhcgg Dec 22, 2025
abedc15
Merge branch 'OpenHUTB:main' into main
rhcgg Dec 22, 2025
95711b4
Merge branch 'OpenHUTB:main' into main
rhcgg Dec 22, 2025
f0aaf02
功能进一步完善
rhcgg Dec 22, 2025
7359c54
Merge branch 'main' of https://github.com/rhcgg/Neural-network
rhcgg Dec 22, 2025
9b3b377
Merge branch 'OpenHUTB:main' into main
rhcgg Dec 22, 2025
c8f61a2
Merge branch 'OpenHUTB:main' into main
rhcgg Dec 22, 2025
6e48694
Merge branch 'OpenHUTB:main' into main
rhcgg Dec 22, 2025
9895ea1
添加一个信息窗口,分担前视窗口压力
rhcgg Dec 22, 2025
153e471
Merge branch 'OpenHUTB:main' into main
rhcgg Dec 22, 2025
bf72468
Merge branch 'OpenHUTB:main' into main
rhcgg Dec 22, 2025
16c3ebd
Merge branch 'OpenHUTB:main' into main
rhcgg Dec 22, 2025
a8907ba
功能完善
rhcgg Dec 22, 2025
b804e95
Merge branch 'OpenHUTB:main' into main
rhcgg Dec 22, 2025
aae6bd5
Merge branch 'OpenHUTB:main' into main
rhcgg Dec 22, 2025
bde3cb5
Merge branch 'OpenHUTB:main' into main
rhcgg Dec 23, 2025
31c452d
内存优化
rhcgg Dec 23, 2025
75fd941
Merge branch 'OpenHUTB:main' into main
rhcgg Dec 24, 2025
f1c458c
修复部分显示界面异常
rhcgg Dec 24, 2025
416eeb1
Merge branch 'main' of https://github.com/rhcgg/Neural-network
rhcgg Dec 24, 2025
ac78c3d
Merge branch 'OpenHUTB:main' into main
rhcgg Dec 24, 2025
8f7c879
完整修复显示界面异常问题
rhcgg Dec 24, 2025
977a0a7
Merge branch 'OpenHUTB:main' into main
rhcgg Dec 25, 2025
453cb30
前视窗口优化
rhcgg Dec 25, 2025
83bb694
Merge branch 'OpenHUTB:main' into main
rhcgg Dec 25, 2025
7a8f3d7
功能优化
rhcgg Dec 25, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/drone_perception/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@
'SHOW_OBJECTS_STATS': True, # 显示物体统计
'SHOW_SYSTEM_STATS': True, # 显示系统统计
'SHOW_PERFORMANCE': True, # 显示性能信息
'SHOW_TRAJECTORY': True, # 显示运动轨迹图
'TRAJECTORY_SIZE': 280, # 轨迹图显示大小(像素)
'TRAJECTORY_MAX_POINTS': 1000, # 轨迹最大记录点数
'TRAJECTORY_LINE_COLOR': (0, 255, 255), # 轨迹线颜色(青色)
'TRAJECTORY_CURRENT_COLOR': (0, 255, 0), # 当前位置颜色(绿色)
'TRAJECTORY_START_COLOR': (255, 255, 0), # 起始位置颜色(黄色)
}
}

Expand Down
213 changes: 210 additions & 3 deletions src/drone_perception/perceptive_drone_explorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ class DefaultConfig:
'SUCCESS_COLOR': (0, 255, 150), 'REFRESH_RATE_MS': 100,
'SHOW_GRID': True, 'GRID_SIZE': 300,
'SHOW_OBJECTS_STATS': True, 'SHOW_SYSTEM_STATS': True,
'SHOW_PERFORMANCE': True}}
'SHOW_PERFORMANCE': True, 'SHOW_TRAJECTORY': True,
'TRAJECTORY_SIZE': 280, 'TRAJECTORY_MAX_POINTS': 1000,
'TRAJECTORY_LINE_COLOR': (0, 255, 255),
'TRAJECTORY_CURRENT_COLOR': (0, 255, 0),
'TRAJECTORY_START_COLOR': (255, 255, 0)}}
SYSTEM = {'LOG_LEVEL': 'INFO', 'LOG_TO_FILE': True, 'LOG_FILENAME': 'drone_log.txt',
'MAX_RECONNECT_ATTEMPTS': 3, 'RECONNECT_DELAY': 2.0,
'ENABLE_HEALTH_CHECK': True, 'HEALTH_CHECK_INTERVAL': 20}
Expand Down Expand Up @@ -1664,6 +1668,10 @@ def __init__(self, window_name=None, width=None, height=None):
self.display_thread = None
self.last_update = time.time()

# 轨迹记录
self.trajectory_points = deque(maxlen=config.DISPLAY['INFO_WINDOW'].get('TRAJECTORY_MAX_POINTS', 1000))
self.start_position = None

self.start()

def start(self):
Expand All @@ -1689,6 +1697,15 @@ def update_info(self, info_data: Dict):
return

try:
# 更新轨迹数据
if 'position' in info_data:
pos = info_data['position']
self.trajectory_points.append((pos[0], pos[1], pos[2]))

# 记录起始位置
if self.start_position is None:
self.start_position = (pos[0], pos[1], pos[2])

if self.info_queue.full():
try:
self.info_queue.get_nowait()
Expand Down Expand Up @@ -1776,6 +1793,119 @@ def _create_waiting_screen(self):

return img

def _draw_trajectory(self, trajectory_points, current_pos, start_pos, size):
"""绘制运动轨迹图"""
try:
# 创建轨迹图(始终返回有效图像)
traj_img = np.zeros((size, size, 3), dtype=np.uint8)
traj_img.fill(30) # 深灰色背景

# 收集所有点用于计算边界
all_points = []
if trajectory_points:
try:
all_points.extend([(float(p[0]), float(p[1])) for p in trajectory_points if len(p) >= 2])
except (IndexError, TypeError, ValueError):
pass
if current_pos and len(current_pos) >= 2:
try:
all_points.append((float(current_pos[0]), float(current_pos[1])))
except (TypeError, ValueError, IndexError):
pass
if start_pos and len(start_pos) >= 2:
try:
all_points.append((float(start_pos[0]), float(start_pos[1])))
except (TypeError, ValueError, IndexError):
pass

if not all_points:
# 没有轨迹点时,返回空白图像
return traj_img

# 计算边界和缩放
xs = [p[0] for p in all_points]
ys = [p[1] for p in all_points]

min_x, max_x = min(xs), max(xs)
min_y, max_y = min(ys), max(ys)

# 添加边距
margin = max((max_x - min_x) * 0.1, (max_y - min_y) * 0.1, 5.0)
range_x = max_x - min_x + 2 * margin
range_y = max_y - min_y + 2 * margin

if range_x == 0:
range_x = 10.0
if range_y == 0:
range_y = 10.0

# 坐标转换函数
def world_to_pixel(wx, wy):
try:
px = int((wx - min_x + margin) / range_x * size)
py = int((wy - min_y + margin) / range_y * size)
px = max(0, min(size - 1, px))
py = max(0, min(size - 1, py))
return px, py
except (ZeroDivisionError, ValueError, TypeError):
return size // 2, size // 2

# 绘制轨迹线
if len(trajectory_points) > 1:
try:
line_color = self.display_config.get('TRAJECTORY_LINE_COLOR', (0, 255, 255))
for i in range(len(trajectory_points) - 1):
try:
p1 = trajectory_points[i]
p2 = trajectory_points[i + 1]
if len(p1) >= 2 and len(p2) >= 2:
px1, py1 = world_to_pixel(p1[0], p1[1])
px2, py2 = world_to_pixel(p2[0], p2[1])
cv2.line(traj_img, (px1, py1), (px2, py2), line_color, 2)
except (IndexError, TypeError, ValueError):
continue
except Exception:
pass

# 绘制起始点
if start_pos and len(start_pos) >= 2:
try:
start_color = self.display_config.get('TRAJECTORY_START_COLOR', (255, 255, 0))
sx, sy = world_to_pixel(start_pos[0], start_pos[1])
cv2.circle(traj_img, (sx, sy), 6, start_color, -1)
cv2.circle(traj_img, (sx, sy), 6, (255, 255, 255), 1)
except (IndexError, TypeError, ValueError):
pass

# 绘制当前位置
if current_pos and len(current_pos) >= 2:
try:
current_color = self.display_config.get('TRAJECTORY_CURRENT_COLOR', (0, 255, 0))
cx, cy = world_to_pixel(current_pos[0], current_pos[1])
cv2.circle(traj_img, (cx, cy), 8, current_color, -1)
cv2.circle(traj_img, (cx, cy), 8, (255, 255, 255), 2)
except (IndexError, TypeError, ValueError):
pass

# 绘制坐标轴
try:
axis_color = (100, 100, 100)
center_x_px, center_y_px = world_to_pixel(0, 0)
if 0 <= center_x_px < size:
cv2.line(traj_img, (center_x_px, 0), (center_x_px, size), axis_color, 1)
if 0 <= center_y_px < size:
cv2.line(traj_img, (0, center_y_px), (size, center_y_px), axis_color, 1)
except Exception:
pass

return traj_img
except Exception as e:
# 发生任何错误时返回空白图像
print(f"⚠️ 绘制轨迹图内部错误: {e}")
traj_img = np.zeros((size, size, 3), dtype=np.uint8)
traj_img.fill(30)
return traj_img

def _render_info_display(self, info_data: Dict) -> np.ndarray:
"""渲染信息显示"""
try:
Expand Down Expand Up @@ -1973,13 +2103,90 @@ def _render_info_display(self, info_data: Dict) -> np.ndarray:
# 将网格图像放到主图像上
img[grid_y:grid_y+grid_size, grid_x:grid_x+grid_size] = grid_resized

# 9. 时间戳
# 9. 运动轨迹图(最左下角)
if self.display_config.get('SHOW_TRAJECTORY', True):
try:
trajectory_size = self.display_config.get('TRAJECTORY_SIZE', 280)
current_pos = info_data.get('position')

# 绘制轨迹图
trajectory_img = self._draw_trajectory(
list(self.trajectory_points),
current_pos,
self.start_position,
trajectory_size
)

if trajectory_img is not None and trajectory_img.size > 0:
# 轨迹图放在最左下角,从底部开始
traj_x = 20 # 左边距
# 从窗口底部向上,留出底部提示文字的空间(约50像素,确保不重叠)
bottom_hint_height = 50
traj_y = self.window_height - trajectory_size - bottom_hint_height

# 确保轨迹图不会超出窗口范围,且不与上方内容重叠(至少距离顶部80像素)
if traj_y >= 80 and traj_y + trajectory_size <= self.window_height - bottom_hint_height:
# 添加轨迹图标题(在轨迹图上方)
traj_title = "Trajectory" # 直接使用英文
cv2.putText(img, traj_title, (traj_x, traj_y - 10),
cv2.FONT_HERSHEY_SIMPLEX, 18 / 30.0, highlight_color, 1)

# 确保图像尺寸匹配
if (traj_y + trajectory_size <= self.window_height and
traj_x + trajectory_size <= self.window_width):
# 将轨迹图放到主图像上
img[traj_y:traj_y+trajectory_size, traj_x:traj_x+trajectory_size] = trajectory_img

# 添加轨迹图图例(在轨迹图右侧,使用英文避免乱码)
legend_x = traj_x + trajectory_size + 15
legend_y = traj_y

if legend_x + 150 < self.window_width:
# 使用英文避免乱码
cv2.putText(img, "Legend:", (legend_x, legend_y),
cv2.FONT_HERSHEY_SIMPLEX, 0.5, text_color, 1)
legend_y += 20

# 起始位置
cv2.circle(img, (legend_x + 7, legend_y + 7), 6,
self.display_config.get('TRAJECTORY_START_COLOR', (255, 255, 0)), -1)
cv2.circle(img, (legend_x + 7, legend_y + 7), 6, (255, 255, 255), 1)
cv2.putText(img, "Start", (legend_x + 20, legend_y + 12),
cv2.FONT_HERSHEY_SIMPLEX, 0.4, text_color, 1)
legend_y += 25

# 当前位置
cv2.circle(img, (legend_x + 7, legend_y + 7), 8,
self.display_config.get('TRAJECTORY_CURRENT_COLOR', (0, 255, 0)), -1)
cv2.circle(img, (legend_x + 7, legend_y + 7), 8, (255, 255, 255), 2)
cv2.putText(img, "Current", (legend_x + 20, legend_y + 12),
cv2.FONT_HERSHEY_SIMPLEX, 0.4, text_color, 1)
legend_y += 25

# 轨迹线
cv2.line(img, (legend_x, legend_y + 7), (legend_x + 20, legend_y + 7),
self.display_config.get('TRAJECTORY_LINE_COLOR', (0, 255, 255)), 2)
cv2.putText(img, "Path", (legend_x + 25, legend_y + 12),
cv2.FONT_HERSHEY_SIMPLEX, 0.4, text_color, 1)

# 显示轨迹点数
point_count = len(self.trajectory_points)
count_text = f"Points: {point_count}"
cv2.putText(img, count_text, (legend_x, legend_y + 30),
cv2.FONT_HERSHEY_SIMPLEX, 0.4, text_color, 1)
except Exception as e:
# 轨迹图绘制失败时不影响其他显示
print(f"⚠️ 绘制轨迹图时出错: {e}")
import traceback
traceback.print_exc()

# 10. 时间戳
if 'timestamp' in info_data:
timestamp = info_data['timestamp']
time_text = f"更新时间: {timestamp}"
img = put_chinese_text(img, time_text, (self.window_width - 200, self.window_height - 10), 15, text_color, 1)

# 10. 底部提示
# 11. 底部提示
hint_text = "按 Q 或 ESC 关闭窗口"
img = put_chinese_text(img, hint_text, (self.window_width // 2 - 80, self.window_height - 30), 15, text_color, 1)

Expand Down
Loading