From 548bb76efca5a89ddd878f245d4a25364f5c5262 Mon Sep 17 00:00:00 2001 From: hubian <908234780@qq.com> Date: Thu, 16 Apr 2026 23:14:10 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BA=BA=E5=91=98=E5=BA=8F=E5=8F=B7?= =?UTF-8?q?=E6=A0=87=E8=AF=86=20-=20=E6=A3=80=E6=B5=8B=E5=88=B0=E7=9A=84?= =?UTF-8?q?=E4=BA=BA=E6=98=BE=E7=A4=BA=20#1,=20#2=20=E7=AD=89=E5=BA=8F?= =?UTF-8?q?=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- local_analyzer.py | 23 +++++++++++++++-------- person_manager.py | 28 ++++++++++++++++++++-------- web/static/style.css | 19 +++++++++++++++++++ 3 files changed, 54 insertions(+), 16 deletions(-) diff --git a/local_analyzer.py b/local_analyzer.py index 4878c2c..81513ec 100644 --- a/local_analyzer.py +++ b/local_analyzer.py @@ -150,30 +150,37 @@ class LocalAnalyzer: if person_result['confirmed_change']: metrics['person_count_change'] = person_count_change - # 记录人员事件 + # 记录人员事件(带序号) for person in person_result['persons']: + person_index = person.get('person_index', 1) + detection_source = person.get('source', 'unknown') + if person['is_new']: events.append({ 'event_type': '人物活动', - 'description': f'新人出现: {person["name"]},当前共 {current_count} 人', + 'description': f'#{person_index} 新人: {person["name"]} [{detection_source}],当前共 {current_count} 人', 'confidence': '高', - 'source': 'local' + 'source': 'local', + 'person_index': person_index }) self.human_count += 1 self.person_change_count += 1 else: events.append({ 'event_type': '人物活动', - 'description': f'已知人员: {person["name"]} [{person.get("source", "detected")}]', + 'description': f'#{person_index} 已知人员: {person["name"]} [{detection_source}]', 'confidence': '高', - 'source': 'local' + 'source': 'local', + 'person_index': person_index }) - # 检测人员进出 + # 检测人员进出(带序号) if person_count_change > 0: + # 列出新进入的人员序号 + new_indices = [p.get('person_index', i+1) for i, p in enumerate(person_result['persons'][-person_count_change:])] events.append({ 'event_type': '人员进出', - 'description': f'检测到 {person_count_change} 人进入,当前共 {current_count} 人 [{person_result.get("detection_source", "")}]', + 'description': f'#{", #".join(map(str, new_indices))} 进入,当前共 {current_count} 人 [{person_result.get("detection_source", "")}]', 'confidence': '高', 'source': 'local' }) @@ -181,7 +188,7 @@ class LocalAnalyzer: elif person_count_change < 0: events.append({ 'event_type': '人员进出', - 'description': f'检测到 {abs(person_count_change)} 人离开,当前剩 {current_count} 人', + 'description': f'{abs(person_count_change)} 人离开,当前剩 {current_count} 人', 'confidence': '高', 'source': 'local' }) diff --git a/person_manager.py b/person_manager.py index ee46eb6..87f5520 100644 --- a/person_manager.py +++ b/person_manager.py @@ -441,6 +441,9 @@ class PersonManager: confirmed_change = False confirmed_persons = [] + # 为每个检测到的人分配序号 + person_index = self.prev_human_count # 从当前人数开始 + # 检查人数变化 prev_count = len(self.prev_persons) @@ -452,16 +455,20 @@ class PersonManager: self.confirmation_buffer[key]['count'] += 1 - # 临时识别人员 + # 临时识别人员并分配序号 temp_persons = [] - for face in faces: + for idx, face in enumerate(faces): bbox = face['bbox'] encoding = self.extract_face_encoding(image, bbox) match_result = self.match_face(encoding) + # 分配人员序号 + person_index_display = idx + 1 # 序号从1开始 + person_info = { - 'person_id': match_result['person_id'] if not match_result['is_new'] else 'unknown', - 'name': match_result['name'], + 'person_id': match_result['person_id'] if not match_result['is_new'] else f"unknown_{person_index_display}", + 'name': match_result['name'] if not match_result['is_new'] else f"Person #{person_index_display}", + 'person_index': person_index_display, # 显示序号 'bbox': bbox, 'is_new': match_result['is_new'], 'confidence': face['confidence'], @@ -477,6 +484,8 @@ class PersonManager: confirmed_persons = temp_persons print(f"[PersonManager] Confirmed: {prev_count} -> {current_count} persons (after {self.config['confirm_frames']} frames)") + for p in confirmed_persons: + print(f" - {p['name']} (#{p['person_index']}) [{p['source']}]") # 清空其他缓冲区 self.confirmation_buffer = {} @@ -487,16 +496,19 @@ class PersonManager: else: # 人数不变,清空变化缓冲区,维持当前状态 if current_count > 0: - # 识别当前人员 + # 识别当前人员并分配序号 temp_persons = [] - for face in faces: + for idx, face in enumerate(faces): bbox = face['bbox'] encoding = self.extract_face_encoding(image, bbox) match_result = self.match_face(encoding) + person_index_display = idx + 1 + person_info = { - 'person_id': match_result['person_id'] if not match_result['is_new'] else 'unknown', - 'name': match_result['name'], + 'person_id': match_result['person_id'] if not match_result['is_new'] else f"unknown_{person_index_display}", + 'name': match_result['name'] if not match_result['is_new'] else f"Person #{person_index_display}", + 'person_index': person_index_display, 'bbox': bbox, 'is_new': match_result['is_new'], 'confidence': face['confidence'], diff --git a/web/static/style.css b/web/static/style.css index e1a0b7f..ef4e09f 100644 --- a/web/static/style.css +++ b/web/static/style.css @@ -371,11 +371,30 @@ button { color: #888; } +.event-card.type-人员进出 .event-type::before, +.event-card.type-人物活动 .event-type::before { + content: "#"; + color: #667eea; +} + +.event-card.source-local .event-type { + display: inline-block; +} + +.event-card.source-local .event-type::after { + content: ""; + margin-right: 5px; +} + .event-desc { font-size: 14px; color: #555; } +.event-desc strong { + color: #667eea; +} + .event-confidence { display: inline-block; font-size: 11px;