From ae1c13589f9ef42c78d887124a60c11deb2dffca Mon Sep 17 00:00:00 2001 From: ericwyuan Date: Fri, 21 Aug 2026 05:54:38 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E4=BA=BA=E7=89=A9=E7=AE=A1=E7=90=86):=20?= =?UTF-8?q?=E5=A4=B4=E5=83=8F=E4=BC=98=E5=85=88=E9=80=89=E7=8B=AC=E7=85=A7?= =?UTF-8?q?=E5=B8=A7=EF=BC=8C=E9=81=BF=E5=85=8D=E5=8F=8C=E4=BA=BA=E5=9B=BE?= =?UTF-8?q?=E5=BD=93=E5=A4=B4=E5=83=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 人物卡片头像挑选策略调整: 1. 优先『独照』帧——该帧只有当前人物一个标签且 face_count=1(双人图不再作为某人头像) 2. 无独照时退而求其次用 face_count 最大的帧 3. 最后按时间序第一张兜底 修复: 一张图出现两人时(如 event_21/frame_3 '人物1, 人物2'),两人卡片都拿双人图做头像、无法区分的问题 --- fam-ui/src/app.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/fam-ui/src/app.py b/fam-ui/src/app.py index a5ba6ac..c2204ae 100644 --- a/fam-ui/src/app.py +++ b/fam-ui/src/app.py @@ -795,11 +795,12 @@ elif page == "👤 人物管理": real_to_label = {v: k for k, v in alias_map.items()} # 聚合每个真实人物出现的帧(时间升序) + # 聚合每个真实人物出现的帧(时间升序),保留原始 person 串供独照判定 person_frames = {} for r in detail_rows: for p in resolve_persons(r['person'], alias_map): person_frames.setdefault(p, []).append( - (r['event_id'], r['frame_index'], r['frame_timestamp'])) + (r['event_id'], r['frame_index'], r['frame_timestamp'], r['person'])) named_keys = [k for k in person_frames if k in real_to_label] st.markdown( @@ -823,19 +824,28 @@ elif page == "👤 人物管理": _meta_cache[event_id] = {} return _meta_cache[event_id] - def person_photo(frames): - """头像优先挑有人脸的帧(face_count 最大),其次按时间序第一张""" - best, best_faces = None, -1 - for eid, fidx, _ in frames: + def person_photo(key, frames): + """头像挑选策略: + 1. 优先『独照』——该帧只有当前人物一个标签且人脸数=1(不会拿双人图当头像) + 2. 无独照时退而求其次:人脸数最多的帧 + 3. 最后按时间序第一张兜底 + """ + solo, best, best_faces = None, None, -1 + for eid, fidx, _ts, person_str in frames: meta = _load_meta(eid) faces = int(meta.get(str(fidx), 0) or 0) - if faces > best_faces: + if faces == 1 and len(resolve_persons(person_str, alias_map)) == 1: + if solo is None: + solo = load_frame_b64(eid, fidx) + elif faces > best_faces: b64 = load_frame_b64(eid, fidx) if b64: best, best_faces = b64, faces + if solo: + return solo if best: return best - for eid, fidx, _ in frames: + for eid, fidx, _ts, _ps in frames: b64 = load_frame_b64(eid, fidx) if b64: return b64 @@ -888,7 +898,7 @@ elif page == "👤 人物管理": is_named = key in real_to_label label = real_to_label.get(key, key) feat = feat_map.get(label) or '暂无特征描述' - photo = person_photo(frames) + photo = person_photo(key, frames) first_ts = parse_ts(frames[0][2]) last_ts = parse_ts(frames[-1][2]) first_str = first_ts.strftime('%m-%d %H:%M') if first_ts else '--'