From a01f8aa386f11a446535799b42bb3a7cd25d9227 Mon Sep 17 00:00:00 2001 From: Tian jianyong <11429339@qq.com> Date: Thu, 18 Dec 2025 17:21:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BF=A1=E6=81=AF=E9=9D=A2?= =?UTF-8?q?=E6=9D=BF=E7=AA=97=E5=8F=A3=E5=A4=A7=E5=B0=8F=E5=AD=97=E4=BD=93?= =?UTF-8?q?=EF=BC=9B=E4=BF=AE=E6=94=B9=E5=B1=95=E5=8E=85=E7=95=8C=E9=9D=A2?= =?UTF-8?q?=E4=B8=BA=E5=85=A8=E5=B1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- face_rec.py | 89 +++++++++++++++++++---------------------------------- 1 file changed, 31 insertions(+), 58 deletions(-) diff --git a/face_rec.py b/face_rec.py index 75fc1a5..8ee3f54 100644 --- a/face_rec.py +++ b/face_rec.py @@ -246,47 +246,18 @@ class FaceRecognitionSystem: self.logger.error(f"无法打开视频文件: {self.video_path}") return False - # 创建视频窗口 - cv2.namedWindow(self.video_window_name, cv2.WINDOW_NORMAL | cv2.WINDOW_GUI_NORMAL) + # 创建视频窗口并设置为全屏 + cv2.namedWindow(self.video_window_name, cv2.WINDOW_NORMAL) - # 获取视频尺寸 + # 设置窗口为全屏模式 + cv2.setWindowProperty(self.video_window_name, cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN) + + # 获取视频信息 video_width = int(self.video_capture.get(cv2.CAP_PROP_FRAME_WIDTH)) video_height = int(self.video_capture.get(cv2.CAP_PROP_FRAME_HEIGHT)) video_fps = self.video_capture.get(cv2.CAP_PROP_FPS) - # 设置窗口大小和位置 - try: - import screeninfo - screen = screeninfo.get_monitors()[0] - - # 设置视频显示尺寸为屏幕的80% - target_width = int(screen.width) - target_height = int(screen.height) - - # 保持宽高比 - scale_width = target_width / video_width - scale_height = target_height / video_height - scale = min(scale_width, scale_height) - - new_width = int(video_width * scale) - new_height = int(video_height * scale) - - # 计算居中位置 - x_pos = (screen.width - new_width) // 2 - y_pos = (screen.height - new_height) // 2 - - # 设置窗口大小和位置 - cv2.resizeWindow(self.video_window_name, new_width, new_height) - cv2.moveWindow(self.video_window_name, x_pos, y_pos) - - self.logger.info(f"视频显示尺寸: {new_width}x{new_height}, 位置: ({x_pos}, {y_pos})") - - except Exception as e: - self.logger.warning(f"无法获取屏幕信息,使用默认尺寸: {e}") - cv2.resizeWindow(self.video_window_name, 1280, 720) - - # 设置窗口置顶 - cv2.setWindowProperty(self.video_window_name, cv2.WND_PROP_TOPMOST, 1) + self.logger.info(f"视频全屏显示: 原始尺寸 {video_width}x{video_height}, FPS: {video_fps:.2f}") self.video_showing = True self.video_start_time = time.time() @@ -390,6 +361,18 @@ class FaceRecognitionSystem: # 在视频帧上绘制机器人状态 frame_with_status = self._draw_robot_status_on_video(frame) + # 获取屏幕尺寸并拉伸视频帧到全屏 + try: + import screeninfo + screen = screeninfo.get_monitors()[0] + screen_width, screen_height = screen.width, screen.height + + # 拉伸视频帧到屏幕尺寸 + frame_with_status = cv2.resize(frame_with_status, (screen_width, screen_height), interpolation=cv2.INTER_LINEAR) + except: + # 如果获取屏幕信息失败,使用默认尺寸 + frame_with_status = cv2.resize(frame_with_status, (1920, 1080), interpolation=cv2.INTER_LINEAR) + # 显示视频帧 cv2.imshow(self.video_window_name, frame_with_status) else: @@ -1477,9 +1460,9 @@ class FaceRecognitionSystem: (255, 255, 255) ) - # 绘制状态信息面板(左上角小窗口) - panel_width = 350 - panel_height = 180 + # 绘制状态信息面板(左下角小窗口) + panel_width = 200 + panel_height = 150 panel_bg = np.zeros((panel_height, panel_width, 3), dtype=np.uint8) panel_bg[:] = (40, 40, 40) @@ -1490,7 +1473,6 @@ class FaceRecognitionSystem: # WebSocket连接状态 ws_status = "已连接" if self.ws_connected else "未连接" - ws_color = (0, 255, 0) if self.ws_connected else (0, 0, 255) status_texts = [ f"质量: {self.display_info['quality']:.1f}", @@ -1507,25 +1489,16 @@ class FaceRecognitionSystem: remaining = max(0, face_duration - elapsed) status_texts.append(f"识别倒计时: {remaining:.1f}秒") - # 使用PIL绘制中文状态文本 + # 使用PIL绘制中文状态文本(全部使用浅灰色) + light_gray = (200, 200, 200) for i, text in enumerate(status_texts): - # WebSocket状态使用特殊颜色 - if "WebSocket" in text: - panel_bg = self.cv2_add_chinese_text( - panel_bg, - text, - (x_offset, y_offset + i * line_spacing), - self.font_small, - ws_color - ) - else: - panel_bg = self.cv2_add_chinese_text( - panel_bg, - text, - (x_offset, y_offset + i * line_spacing), - self.font_small, - (255, 255, 255) - ) + panel_bg = self.cv2_add_chinese_text( + panel_bg, + text, + (x_offset, y_offset + i * line_spacing), + self.font_small, + light_gray + ) # 将小面板叠加到画面左下角 h, w = display_frame.shape[:2]