From a4e8bbfe7ccb744a7a68079c272840e384ea9dd1 Mon Sep 17 00:00:00 2001 From: Tian jianyong <11429339@qq.com> Date: Sun, 28 Dec 2025 17:58:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E6=8D=95=E6=8D=89=E6=A1=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- face_rec.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/face_rec.py b/face_rec.py index 729cb31..909f497 100644 --- a/face_rec.py +++ b/face_rec.py @@ -1279,7 +1279,7 @@ class FaceRecognitionSystem: img = cv2.cvtColor(np.array(img_pil), cv2.COLOR_RGB2BGR) return img - def draw_info_on_frame(self, frame: np.ndarray, mirrored: bool = False) -> np.ndarray: + def draw_info_on_frame(self, frame: np.ndarray) -> np.ndarray: """在帧上绘制检测和识别信息""" display_frame = frame.copy() h, w = display_frame.shape[:2] @@ -1292,11 +1292,6 @@ class FaceRecognitionSystem: x_max = int(box['x_max']) y_max = int(box['y_max']) - # 镜像翻转时调整坐标 - if mirrored: - x_min = w - 1 - x_max - x_max = w - 1 - x_min - # 根据识别状态选择颜色 if self.display_info['person_name']: # 已识别 - 绿色 @@ -1820,8 +1815,17 @@ class FaceRecognitionSystem: # 镜像翻转:使画面与实际场景一致(在绘制信息之前) frame = cv2.flip(frame, 1) - # 绘制信息(传入镜像状态,由 draw_info_on_frame 内部处理坐标翻转) - display_frame = self.draw_info_on_frame(frame, mirrored=True) + # 调整 face_box 坐标以适应镜像翻转 + if self.display_info['face_detected'] and self.display_info['face_box']: + h_flip, w_flip = frame.shape[:2] + box = self.display_info['face_box'] + x_min = int(box['x_min']) + x_max = int(box['x_max']) + # 水平翻转坐标 + self.display_info['face_box']['x_min'] = w_flip - 1 - x_max + self.display_info['face_box']['x_max'] = w_flip - 1 - x_min + + # 绘制信息 display_frame = self.draw_info_on_frame(frame) # 绘制人脸轮廓引导框(屏幕中央)