From fd5aedb3f9437617d2b6be49d4859a21c63bf94a Mon Sep 17 00:00:00 2001 From: Tian jianyong <11429339@qq.com> Date: Sun, 28 Dec 2025 17:48:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=BC=95=E5=AF=BC=E6=A1=86?= =?UTF-8?q?=EF=BC=8C=E8=B0=83=E6=95=B4=E4=BA=BA=E8=84=B8=E6=A1=86=E7=9A=84?= =?UTF-8?q?=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.yaml | 4 ++-- face_rec.py | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/config.yaml b/config.yaml index 6bc9f4a..154653e 100644 --- a/config.yaml +++ b/config.yaml @@ -41,11 +41,11 @@ camera: face_detection: frame_interval: 10 # 检测帧间隔(每N帧检测一次) quality_threshold: 10 # 图像质量阈值(Laplacian方差) - min_face_size: 80 # 最小人脸尺寸(像素) + min_face_size: 60 # 最小人脸尺寸(像素),越小检测距离越远 face_present_duration: 2.0 # 持续出现时长(秒)才触发识别 max_yaw: 20.0 # 最大允许的偏航角(度),超过此角度视为侧脸 max_pitch: 20.0 # 最大允许的俯仰角(度),超过此角度视为抬头或低头 - no_face_threshold: 30 # 人脸消失计数器阈值(帧),连续N帧没有检测到人脸才清空 + no_face_threshold: 60 # 人脸消失计数器阈值(帧),约2秒没有检测到人脸才清空 # 人脸识别配置 face_recognition: diff --git a/face_rec.py b/face_rec.py index c0e64dd..2c4f37a 100644 --- a/face_rec.py +++ b/face_rec.py @@ -1815,9 +1815,30 @@ class FaceRecognitionSystem: # 镜像翻转:使画面与实际场景一致(在绘制信息之前) frame = cv2.flip(frame, 1) + # 调整人脸框坐标以适应镜像翻转 + if self.display_info['face_box']: + h, w = frame.shape[:2] + box = self.display_info['face_box'] + x_min = int(box['x_min']) + x_max = int(box['x_max']) + # 水平翻转坐标:new_x = width - 1 - old_x + self.display_info['face_box']['x_min'] = w - 1 - x_max + self.display_info['face_box']['x_max'] = w - 1 - x_min + # 绘制信息 display_frame = self.draw_info_on_frame(frame) + # 绘制人脸轮廓引导框(屏幕中央) + h, w = display_frame.shape[:2] + center_x = w // 2 + center_y = h // 2 + # 椭圆参数:中心点、长轴、短轴、旋转角度、起始角度、结束角度 + cv2.ellipse(display_frame, (center_x, center_y), (120, 160), 0, 0, 360, (0, 200, 0), 2) + + # 添加提示文字 + cv2.putText(display_frame, "请将脸部对准圆圈内", (center_x - 100, center_y + 200), + cv2.FONT_HERSHEY_SIMPLEX, 0.8, (0, 200, 0), 2) + # 使用缓存的屏幕尺寸拉伸视频帧到全屏 display_frame = cv2.resize(display_frame, (self.screen_width, self.screen_height), interpolation=cv2.INTER_LINEAR)