Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 10 additions & 4 deletions src/Unmanned_car_perceive/drawer.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,17 @@ def display_camera(self):
def display_fps(self, fps):
"""在屏幕右上角显示实时帧率"""
fps_text = self.small_font.render(f'FPS: {fps:.1f}', True, (200, 200, 255))
# 显示在右上角,摄像头图像的右侧
fps_x = self.screen.get_width() - 120 # 右边距20,宽度100
fps_y = 20
self.screen.blit(fps_text, (fps_x, fps_y))

# 确保FPS显示在摄像头图像之上,不会被遮挡
fps_x = self.screen.get_width() - 150 # 调整位置,确保不被摄像头图像覆盖
fps_y = 10 # 放在最顶部

# 添加背景框以提高可读性
text_rect = fps_text.get_rect()
background_rect = pygame.Rect(fps_x - 5, fps_y - 2, text_rect.width + 10, text_rect.height + 4)
pygame.draw.rect(self.screen, (0, 0, 0, 180), background_rect, border_radius=3)

self.screen.blit(fps_text, (fps_x, fps_y))
def draw_camera(self, image_array):
"""绘制摄像头图像(兼容旧代码)"""
# 将图像存储起来供display_camera使用
Expand Down
6 changes: 1 addition & 5 deletions src/Unmanned_car_perceive/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,18 +256,14 @@ def on_tick(self):
# 🆕 显示摄像头图像
self.drawer.display_camera()

# 🆕 显示帧率
# 🆕 显示帧率 - 确保这个调用在最后,显示在最上层
self.drawer.display_fps(self.fps)

# 🆕 新增:显示摄像头图像
self.drawer.display_camera()

# 更新观察者视角跟随车辆
self.update_spectator()

except Exception as e:
print(f"⚠️ 更新车辆状态失败: {e}")

def update_spectator(self):
"""更新观察者视角"""
try:
Expand Down
Loading