修正文字的位置

This commit is contained in:
Tian jianyong 2025-12-28 18:18:51 +08:00
parent fdf2f311f1
commit 8bc972d623

View File

@ -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))
# 使用缓存的屏幕尺寸拉伸视频帧到全屏