feat: 设置面板分组整理 + 人员时间精确到秒

This commit is contained in:
2026-04-17 10:49:44 +08:00
parent 57437de02d
commit 79979b2ffb
4 changed files with 105 additions and 68 deletions

View File

@@ -61,25 +61,30 @@ class PersonManager:
# 配置
self.config = {
'face_match_threshold': 0.6, # 人脸匹配阈值
'unknown_person_id': 'unknown', # 未知人员ID
'max_persons': 100, # 最大人员数量
'face_match_threshold': 0.6,
'unknown_person_id': 'unknown',
'max_persons': 100,
# 方案1: 参数调整
'mediapipe_min_confidence': 0.3, # 降低阈值,更容易检测
'mediapipe_model_selection': 1, # 1: 远距离模型
'haar_scale_factor': 1.05, # Haar更细粒度
'haar_min_neighbors': 2, # 降低邻居要求
# 方案2: 连续性判断
'confirm_frames': 3, # 连续几帧确认
'leave_frames': 2, # 连续几帧消失才算离开
# YOLO 检测参数
'yolo_min_confidence': 0.3,
'confirm_frames': 3,
'leave_frames': 2,
}
# 方案2: 追踪状态(连续判断)
self.tracked_persons = {} # {person_id: {'frames': count, 'confirmed': bool}}
self.prev_persons = [] # 前一帧检测到的人
self.confirmation_buffer = {} # 确认缓冲区
# 从配置文件读取参数
try:
from config import config_mgr
self.config['yolo_min_confidence'] = config_mgr.get('yolo_min_confidence', 0.3)
self.config['face_match_threshold'] = config_mgr.get('face_match_threshold', 0.6)
self.config['confirm_frames'] = config_mgr.get('confirm_frames', 3)
self.config['leave_frames'] = config_mgr.get('leave_frames', 2)
except:
pass
# 追踪状态(连续判断)
self.tracked_persons = {}
self.prev_persons = []
self.confirmation_buffer = {}
# 统计
self.total_detections = 0
@@ -151,6 +156,8 @@ class PersonManager:
if self.yolo_detector is None:
return persons
min_conf = self.config.get('yolo_min_confidence', 0.3)
try:
results = self.yolo_detector(image, classes=[0], verbose=False) # class 0 = person
@@ -160,7 +167,6 @@ class PersonManager:
conf = box.conf[0].item()
# 置信度过滤
min_conf = self.config.get('mediapipe_min_confidence', 0.3)
if conf < min_conf:
continue
@@ -370,7 +376,7 @@ class PersonManager:
dict: {'person_id': str, 'name': str, 'is_new': bool}
"""
if threshold is None:
threshold = self.config['face_match_threshold']
threshold = self.config.get('face_match_threshold', 0.6)
if face_encoding is None:
return {'person_id': 'unknown', 'name': 'Unknown', 'is_new': False}
@@ -621,8 +627,8 @@ class PersonManager:
'person_id': p['person_id'],
'name': p['name'],
'visit_count': p['visit_count'],
'first_seen': p['first_seen'],
'last_seen': p['last_seen']
'first_seen': p['first_seen'], # 已经精确到秒
'last_seen': p['last_seen'], # 已经精确到秒
}
for p in self.persons.values()
]