修改椭圆大小,修正捕捉框 bug
This commit is contained in:
parent
fd5aedb3f9
commit
cefc5d733c
32
face_rec.py
32
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) -> np.ndarray:
|
||||
def draw_info_on_frame(self, frame: np.ndarray, mirrored: bool = False) -> np.ndarray:
|
||||
"""在帧上绘制检测和识别信息"""
|
||||
display_frame = frame.copy()
|
||||
h, w = display_frame.shape[:2]
|
||||
@ -1292,6 +1292,11 @@ 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']:
|
||||
# 已识别 - 绿色
|
||||
@ -1815,17 +1820,8 @@ 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
|
||||
|
||||
# 绘制信息
|
||||
# 绘制信息(传入镜像状态,由 draw_info_on_frame 内部处理坐标翻转)
|
||||
display_frame = self.draw_info_on_frame(frame, mirrored=True)
|
||||
display_frame = self.draw_info_on_frame(frame)
|
||||
|
||||
# 绘制人脸轮廓引导框(屏幕中央)
|
||||
@ -1833,11 +1829,15 @@ class FaceRecognitionSystem:
|
||||
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.ellipse(display_frame, (center_x, center_y), (75, 100), 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)
|
||||
# 添加提示文字(使用中文支持函数)
|
||||
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
|
||||
display_frame = self.cv2_add_chinese_text(display_frame, guide_text, (text_x, text_y), self.font_medium, (0, 200, 0))
|
||||
|
||||
# 使用缓存的屏幕尺寸拉伸视频帧到全屏
|
||||
display_frame = cv2.resize(display_frame, (self.screen_width, self.screen_height), interpolation=cv2.INTER_LINEAR)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user