feat: 三方案改进检测准确度 - YOLO优先、参数调整、连续性判断

This commit is contained in:
2026-04-16 22:35:51 +08:00
parent d6693f9fd0
commit 7875cca69e
6 changed files with 272 additions and 105 deletions

View File

@@ -134,55 +134,70 @@ class LocalAnalyzer:
# 方法1MediaPipe 人脸检测 + 人员识别(优先)
if HAS_PERSON_MANAGER and use_mediapipe:
print(f"[LocalAnalyzer] Using MediaPipe face detection...")
print(f"[LocalAnalyzer] Using PersonManager for detection...")
person_result = person_manager.analyze_image(image_path, save_new_person=True)
metrics['person_count'] = person_result['total_count']
metrics['new_persons'] = person_result['new_count']
metrics['known_persons'] = person_result['known_count']
metrics['detection_source'] = person_result.get('detection_source', 'unknown')
prev_person_count = self.prev_human_count
person_count_change = person_result['total_count'] - prev_person_count
metrics['person_count_change'] = person_count_change
current_count = person_result['current_count']
person_count_change = current_count - prev_person_count
# 记录人员事件
for person in person_result['persons']:
if person['is_new']:
# 只有确认的变化才记录
if person_result['confirmed_change']:
metrics['person_count_change'] = person_count_change
# 记录人员事件
for person in person_result['persons']:
if person['is_new']:
events.append({
'event_type': '人物活动',
'description': f'新人出现: {person["name"]},当前共 {current_count}',
'confidence': '',
'source': 'local'
})
self.human_count += 1
self.person_change_count += 1
else:
events.append({
'event_type': '人物活动',
'description': f'已知人员: {person["name"]} [{person.get("source", "detected")}]',
'confidence': '',
'source': 'local'
})
# 检测人员进出
if person_count_change > 0:
events.append({
'event_type': '物活动',
'description': f'新人出现: {person["name"]},当前共 {person_result["total_count"]}',
'event_type': '员进出',
'description': f'检测到 {person_count_change} 人进入,当前共 {current_count} 人 [{person_result.get("detection_source", "")}]',
'confidence': '',
'source': 'local'
})
self.human_count += 1
self.person_change_count += 1
else:
elif person_count_change < 0:
events.append({
'event_type': '物活动',
'description': f'已知人员: {person["name"]}',
'event_type': '员进出',
'description': f'检测到 {abs(person_count_change)} 人离开,当前剩 {current_count}',
'confidence': '',
'source': 'local'
})
# 检测人员进出
if person_count_change > 0:
events.append({
'event_type': '人员进出',
'description': f'检测到 {person_count_change} 人进入,当前共 {person_result["total_count"]}',
'confidence': '',
'source': 'local'
})
self.person_change_count += 1
elif person_count_change < 0:
events.append({
'event_type': '人员进出',
'description': f'检测到 {abs(person_count_change)} 人离开,当前剩 {person_result["total_count"]}',
'confidence': '',
'source': 'local'
})
self.person_change_count += 1
self.prev_human_count = person_result['total_count']
self.person_change_count += 1
self.prev_human_count = current_count
else:
# 没有确认的变化,只记录当前状态
metrics['person_count_change'] = 0
if current_count > 0:
events.append({
'event_type': '人物活动',
'description': f'检测到 {current_count} 人(状态稳定)',
'confidence': '',
'source': 'local'
})
# 方法2Haar Cascade 人体检测(备用或并行)
if use_haar and self.human_cascade is not None: