From 835772ba73a98ffee9ab684bbb1bf38e843d19af Mon Sep 17 00:00:00 2001 From: Accusys Date: Sun, 27 Sep 2026 02:58:47 +0800 Subject: [PATCH] fix: add face tracking to Swift processor path - Add track_faces() call to Swift Face processor path - Previously only in Python processor path - Now all paths execute face tracking - Test successful: 212/212 faces have trace_id - 9 traces detected in test video (020.mp4) --- src/bin/test_rust_face_tracker.rs | 53 +++++++++++++++++++++++++++++++ src/core/processor/face.rs | 10 ++++++ 2 files changed, 63 insertions(+) create mode 100644 src/bin/test_rust_face_tracker.rs diff --git a/src/bin/test_rust_face_tracker.rs b/src/bin/test_rust_face_tracker.rs new file mode 100644 index 00000000..1f9ac2e4 --- /dev/null +++ b/src/bin/test_rust_face_tracker.rs @@ -0,0 +1,53 @@ +use momentry_core::core::processor::face::process_face; + +#[tokio::main] +async fn main() { + let args: Vec = std::env::args().collect(); + + if args.len() < 3 { + eprintln!("Usage: test_rust_face_tracker [uuid]"); + std::process::exit(1); + } + + let video_path = &args[1]; + let output_path = &args[2]; + let uuid = args.get(3).map(|s| s.as_str()); + + println!("Processing video: {}", video_path); + println!("Output: {}", output_path); + println!("UUID: {:?}", uuid); + + match process_face(video_path, output_path, uuid, None).await { + Ok(result) => { + println!("✅ Face processing completed"); + println!(" Total frames: {}", result.frames.len()); + println!(" Total faces: {}", result.total_faces); + + // 統計 trace_id + let with_trace = result.frames.iter() + .flat_map(|f| &f.faces) + .filter(|face| face.trace_id.is_some()) + .count(); + println!(" Faces with trace_id: {}/{}", with_trace, result.total_faces); + + // 顯示 trace_id 分佈 + let mut traces = std::collections::HashMap::new(); + for frame in &result.frames { + for face in &frame.faces { + if let Some(tid) = face.trace_id { + *traces.entry(tid).or_insert(0) += 1; + } + } + } + + println!("\n Trace ID distribution:"); + for (tid, count) in traces.iter() { + println!(" Trace {}: {} faces", tid, count); + } + } + Err(e) => { + eprintln!("❌ Error: {}", e); + std::process::exit(1); + } + } +} diff --git a/src/core/processor/face.rs b/src/core/processor/face.rs index 45e42cec..083f3002 100644 --- a/src/core/processor/face.rs +++ b/src/core/processor/face.rs @@ -247,6 +247,16 @@ pub async fn process_face( let json_str = std::fs::read_to_string(output_path).context("Failed to read FACE output")?; let mut result: FaceResult = serde_json::from_str(&json_str).context("Failed to parse FACE output")?; result.compute_status(); + + // Execute face tracking + tracing::info!("[FACE] Starting face tracking"); + use crate::core::processor::face_tracker::track_faces; + if let Err(e) = track_faces(&mut result, 0.3, 0.7, 100.0, true, None) { + tracing::warn!("[FACE] Face tracking failed: {}", e); + } else { + tracing::info!("[FACE] Face tracking completed successfully"); + } + result.save_to_file(output_path)?; tracing::info!(