From bfa846f679021eef49ecdf3fb39fb69361b7a519 Mon Sep 17 00:00:00 2001 From: Accusys Date: Mon, 28 Sep 2026 10:34:59 +0800 Subject: [PATCH] fix: update rust_store_traced_faces to match actual face.json format MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 問題: - face.json 的臉部數據結構不匹配 - bbox 是嵌套對象,不是直接字段 修復: - 更新 FaceDetection 結構體 - 添加 BBox 結構體 - 支持 confidence, embedding, pose, landmarks 等字段 測試: - ✅ CLI 執行成功 - ✅ JSON 解析成功 - ✅ face_traced.json 生成 - ⚠️ Face tracking 邏輯需要優化 已知問題: - Traces 數量不正確 (212 vs 9) - Face tracking 邏輯過於簡化 - 需要調用 face_tracker.py 或實現完整邏輯 下一步: - 集成 face_tracker.py - 支持雙格式輸出 - PostgreSQL/Qdrant 更新 --- .../rust/src/bin/rust_store_traced_faces.rs | 50 ++++++++----------- 1 file changed, 21 insertions(+), 29 deletions(-) diff --git a/tools/cli/rust/src/bin/rust_store_traced_faces.rs b/tools/cli/rust/src/bin/rust_store_traced_faces.rs index dd0a0927..defa9044 100644 --- a/tools/cli/rust/src/bin/rust_store_traced_faces.rs +++ b/tools/cli/rust/src/bin/rust_store_traced_faces.rs @@ -25,16 +25,28 @@ struct Args { #[derive(Debug, Serialize, Deserialize, Clone)] struct FaceDetection { - frame: i64, + #[serde(skip_serializing_if = "Option::is_none")] + trace_id: Option, + confidence: f32, + bbox: BBox, + #[serde(skip_serializing_if = "Option::is_none")] + embedding: Option>, + #[serde(skip_serializing_if = "Option::is_none")] + pose: Option, + #[serde(skip_serializing_if = "Option::is_none")] + landmarks: Option, + #[serde(skip_serializing_if = "Option::is_none")] + lips: Option, + #[serde(rename = "captureQuality", skip_serializing_if = "Option::is_none")] + capture_quality: Option, +} + +#[derive(Debug, Serialize, Deserialize, Clone)] +struct BBox { x: i32, y: i32, width: i32, height: i32, - confidence: f32, - #[serde(skip_serializing_if = "Option::is_none")] - trace_id: Option, - #[serde(skip_serializing_if = "Option::is_none")] - embedding: Option>, } #[derive(Debug, Serialize, Deserialize, Clone)] @@ -55,19 +67,15 @@ struct TraceInfo { #[derive(Debug, Serialize, Deserialize, Clone)] struct TracePoint { frame: i64, - x: i32, - y: i32, - width: i32, - height: i32, + bbox: BBox, confidence: f32, } #[derive(Debug, Serialize, Deserialize)] struct FaceData { fps: f64, + frame_count: i64, frames: Vec, - #[serde(skip_serializing_if = "Option::is_none")] - traces: Option>, } #[derive(Debug, Serialize)] @@ -131,25 +139,14 @@ fn run_face_tracking( min_trace_len: usize, min_confidence: f32, ) -> Result> { - // Simplified face tracking - // In a real implementation, this would: - // 1. Calculate embeddings - // 2. Use IoU matching - // 3. Track across frames - - // For now, assign trace_id based on spatial proximity let mut traces: HashMap = HashMap::new(); let mut next_trace_id = 1; - // Group faces by approximate position for frame in &mut face_data.frames { for face in &mut frame.faces { - // Simple trace assignment (placeholder logic) - // In real implementation, would use tracking algorithm let trace_id = next_trace_id; face.trace_id = Some(trace_id); - // Update trace info let trace_key = trace_id.to_string(); let trace = traces.entry(trace_key).or_insert(TraceInfo { trace_id, @@ -161,10 +158,7 @@ fn run_face_tracking( trace.total_appearances += 1; trace.path.push(TracePoint { frame: frame.frame, - x: face.x, - y: face.y, - width: face.width, - height: face.height, + bbox: face.bbox.clone(), confidence: face.confidence, }); @@ -172,7 +166,6 @@ fn run_face_tracking( } } - // Calculate average confidence for each trace for trace in traces.values_mut() { if !trace.path.is_empty() { let sum: f32 = trace.path.iter().map(|p| p.confidence).sum(); @@ -180,7 +173,6 @@ fn run_face_tracking( } } - // Filter traces if min_trace_len > 0 || min_confidence > 0.0 { traces.retain(|_, trace| { trace.total_appearances >= min_trace_len