fix: PeopleView 从 cluster 数据提取 trace_ids 和 representative_trace
- 构建 faceIdToTraceId 映射 - 从 representative_face.face_id 找到 trace_id - 为每个 cluster 设置 trace_ids 字段 - 设置 representative_trace 字段 - 修复 group 缩略图无法显示的问题
This commit is contained in:
@@ -2056,6 +2056,8 @@ async function loadClusterResults() {
|
|||||||
}
|
}
|
||||||
// Build cluster_id → faces[] mapping from frames
|
// Build cluster_id → faces[] mapping from frames
|
||||||
const clusterFacesMap: Record<string, any[]> = {}
|
const clusterFacesMap: Record<string, any[]> = {}
|
||||||
|
const clusterTraceIdsMap: Record<string, Set<number>> = {}
|
||||||
|
const faceIdToTraceId: Record<string, number> = {}
|
||||||
for (const f of frames) {
|
for (const f of frames) {
|
||||||
for (const face of (f.faces || [])) {
|
for (const face of (f.faces || [])) {
|
||||||
const cid = face.cluster_id
|
const cid = face.cluster_id
|
||||||
@@ -2066,15 +2068,35 @@ async function loadClusterResults() {
|
|||||||
frame: f.frame,
|
frame: f.frame,
|
||||||
timestamp: f.timestamp,
|
timestamp: f.timestamp,
|
||||||
confidence: face.confidence,
|
confidence: face.confidence,
|
||||||
cluster_id: cid
|
cluster_id: cid,
|
||||||
|
trace_id: face.trace_id
|
||||||
})
|
})
|
||||||
|
if (face.trace_id !== undefined && face.trace_id !== null) {
|
||||||
|
if (!clusterTraceIdsMap[cid]) clusterTraceIdsMap[cid] = new Set()
|
||||||
|
clusterTraceIdsMap[cid].add(face.trace_id)
|
||||||
|
if (face.face_id) {
|
||||||
|
faceIdToTraceId[face.face_id] = face.trace_id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Assign faces to each cluster
|
}
|
||||||
|
}
|
||||||
|
// Assign faces and trace_ids to each cluster
|
||||||
for (const c of groups) {
|
for (const c of groups) {
|
||||||
const cid = c.cluster_id || c.group_id
|
const cid = c.cluster_id || c.group_id
|
||||||
c.member_faces = clusterFacesMap[cid] || []
|
c.member_faces = clusterFacesMap[cid] || []
|
||||||
c.face_count = c.member_faces.length
|
c.face_count = c.member_faces.length
|
||||||
|
c.trace_ids = Array.from(clusterTraceIdsMap[cid] || [])
|
||||||
|
// Set representative_trace from representative_face
|
||||||
|
if (c.representative_face?.face_id) {
|
||||||
|
const repTraceId = faceIdToTraceId[c.representative_face.face_id]
|
||||||
|
if (repTraceId !== undefined) {
|
||||||
|
c.representative_trace = repTraceId
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Fallback to first trace_id
|
||||||
|
if (c.representative_trace === undefined && c.trace_ids.length > 0) {
|
||||||
|
c.representative_trace = c.trace_ids[0]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (groups.length) {
|
if (groups.length) {
|
||||||
setClusterResults(fileUuid, groups)
|
setClusterResults(fileUuid, groups)
|
||||||
|
|||||||
Reference in New Issue
Block a user