fix: update rust_store_traced_faces to match actual face.json format
問題: - 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 更新
This commit is contained in:
@@ -25,16 +25,28 @@ struct Args {
|
|||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
struct FaceDetection {
|
struct FaceDetection {
|
||||||
frame: i64,
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
trace_id: Option<i32>,
|
||||||
|
confidence: f32,
|
||||||
|
bbox: BBox,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
embedding: Option<Vec<f32>>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pose: Option<serde_json::Value>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
landmarks: Option<serde_json::Value>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
lips: Option<serde_json::Value>,
|
||||||
|
#[serde(rename = "captureQuality", skip_serializing_if = "Option::is_none")]
|
||||||
|
capture_quality: Option<f32>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
|
struct BBox {
|
||||||
x: i32,
|
x: i32,
|
||||||
y: i32,
|
y: i32,
|
||||||
width: i32,
|
width: i32,
|
||||||
height: i32,
|
height: i32,
|
||||||
confidence: f32,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
trace_id: Option<i32>,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
embedding: Option<Vec<f32>>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
@@ -55,19 +67,15 @@ struct TraceInfo {
|
|||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
struct TracePoint {
|
struct TracePoint {
|
||||||
frame: i64,
|
frame: i64,
|
||||||
x: i32,
|
bbox: BBox,
|
||||||
y: i32,
|
|
||||||
width: i32,
|
|
||||||
height: i32,
|
|
||||||
confidence: f32,
|
confidence: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
struct FaceData {
|
struct FaceData {
|
||||||
fps: f64,
|
fps: f64,
|
||||||
|
frame_count: i64,
|
||||||
frames: Vec<FaceFrame>,
|
frames: Vec<FaceFrame>,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
traces: Option<HashMap<String, TraceInfo>>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
@@ -131,25 +139,14 @@ fn run_face_tracking(
|
|||||||
min_trace_len: usize,
|
min_trace_len: usize,
|
||||||
min_confidence: f32,
|
min_confidence: f32,
|
||||||
) -> Result<HashMap<String, TraceInfo>> {
|
) -> Result<HashMap<String, TraceInfo>> {
|
||||||
// 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<String, TraceInfo> = HashMap::new();
|
let mut traces: HashMap<String, TraceInfo> = HashMap::new();
|
||||||
let mut next_trace_id = 1;
|
let mut next_trace_id = 1;
|
||||||
|
|
||||||
// Group faces by approximate position
|
|
||||||
for frame in &mut face_data.frames {
|
for frame in &mut face_data.frames {
|
||||||
for face in &mut frame.faces {
|
for face in &mut frame.faces {
|
||||||
// Simple trace assignment (placeholder logic)
|
|
||||||
// In real implementation, would use tracking algorithm
|
|
||||||
let trace_id = next_trace_id;
|
let trace_id = next_trace_id;
|
||||||
face.trace_id = Some(trace_id);
|
face.trace_id = Some(trace_id);
|
||||||
|
|
||||||
// Update trace info
|
|
||||||
let trace_key = trace_id.to_string();
|
let trace_key = trace_id.to_string();
|
||||||
let trace = traces.entry(trace_key).or_insert(TraceInfo {
|
let trace = traces.entry(trace_key).or_insert(TraceInfo {
|
||||||
trace_id,
|
trace_id,
|
||||||
@@ -161,10 +158,7 @@ fn run_face_tracking(
|
|||||||
trace.total_appearances += 1;
|
trace.total_appearances += 1;
|
||||||
trace.path.push(TracePoint {
|
trace.path.push(TracePoint {
|
||||||
frame: frame.frame,
|
frame: frame.frame,
|
||||||
x: face.x,
|
bbox: face.bbox.clone(),
|
||||||
y: face.y,
|
|
||||||
width: face.width,
|
|
||||||
height: face.height,
|
|
||||||
confidence: face.confidence,
|
confidence: face.confidence,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -172,7 +166,6 @@ fn run_face_tracking(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate average confidence for each trace
|
|
||||||
for trace in traces.values_mut() {
|
for trace in traces.values_mut() {
|
||||||
if !trace.path.is_empty() {
|
if !trace.path.is_empty() {
|
||||||
let sum: f32 = trace.path.iter().map(|p| p.confidence).sum();
|
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 {
|
if min_trace_len > 0 || min_confidence > 0.0 {
|
||||||
traces.retain(|_, trace| {
|
traces.retain(|_, trace| {
|
||||||
trace.total_appearances >= min_trace_len
|
trace.total_appearances >= min_trace_len
|
||||||
|
|||||||
Reference in New Issue
Block a user