测试捕捉框

This commit is contained in:
Tian jianyong 2025-12-28 17:58:07 +08:00
parent cefc5d733c
commit a4e8bbfe7c

View File

@ -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)
# 绘制人脸轮廓引导框(屏幕中央)