From 8bc972d623035732bb6b45f0200baa8d583ce10d Mon Sep 17 00:00:00 2001 From: Tian jianyong <11429339@qq.com> Date: Sun, 28 Dec 2025 18:18:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E6=96=87=E5=AD=97=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 --- face_rec.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/face_rec.py b/face_rec.py index 4abe40c..112226d 100644 --- a/face_rec.py +++ b/face_rec.py @@ -1836,14 +1836,18 @@ class FaceRecognitionSystem: center_x = w // 2 center_y = h // 2 # 椭圆参数:中心点、宽半轴、高半轴、旋转角度、起始角度、结束角度 - cv2.ellipse(display_frame, (center_x, center_y), (150, 200), 0, 0, 360, (0, 200, 0), 2) + cv2.ellipse(display_frame, (center_x, center_y), (150, 200), 0, 0, 360, (0, 200, 0), 3) # 添加提示文字(使用中文支持函数) guide_text = "请将脸部对准圆圈内" - # 计算文字居中位置 - text_size = cv2.getTextSize(guide_text, cv2.FONT_HERSHEY_SIMPLEX, 0.8, 2)[0] - text_x = center_x - text_size[0] // 2 - text_y = center_y + 150 + # 计算文字位置:距离底部40像素,居中显示 + # 使用PIL计算中文文字的实际宽度 + img_temp = Image.new('RGB', (1, 1)) + draw_temp = ImageDraw.Draw(img_temp) + bbox = draw_temp.textbbox((0, 0), guide_text, font=self.font_medium) + text_width = bbox[2] - bbox[0] + text_x = center_x - text_width // 2 + text_y = h - 40 display_frame = self.cv2_add_chinese_text(display_frame, guide_text, (text_x, text_y), self.font_medium, (0, 200, 0)) # 使用缓存的屏幕尺寸拉伸视频帧到全屏