feat: 自動產生 face_id(face_{frame}_{idx})於 face.json 儲存前
This commit is contained in:
@@ -116,6 +116,19 @@ impl FaceResult {
|
|||||||
self.metadata = Some(metadata);
|
self.metadata = Some(metadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Generate face_id for faces that don't have one.
|
||||||
|
/// Format: face_{frame}_{index_within_frame}
|
||||||
|
pub fn ensure_face_ids(&mut self) {
|
||||||
|
for frame in &mut self.frames {
|
||||||
|
let frame_num = frame.frame;
|
||||||
|
for (idx, face) in frame.faces.iter_mut().enumerate() {
|
||||||
|
if face.face_id.is_none() {
|
||||||
|
face.face_id = Some(format!("face_{}_{}", frame_num, idx));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn save_to_file(&self, path: &str) -> Result<()> {
|
pub fn save_to_file(&self, path: &str) -> Result<()> {
|
||||||
self.save_to_file_with_source(path, None, None)
|
self.save_to_file_with_source(path, None, None)
|
||||||
}
|
}
|
||||||
@@ -281,6 +294,7 @@ pub async fn process_face(
|
|||||||
|
|
||||||
result.compute_status();
|
result.compute_status();
|
||||||
result.add_metadata("face", "swift_face", uuid);
|
result.add_metadata("face", "swift_face", uuid);
|
||||||
|
result.ensure_face_ids();
|
||||||
result.save_to_file(output_path)?;
|
result.save_to_file(output_path)?;
|
||||||
|
|
||||||
tracing::info!(
|
tracing::info!(
|
||||||
@@ -431,6 +445,7 @@ pub async fn process_face(
|
|||||||
tracing::info!("[FACE] Face tracking completed successfully");
|
tracing::info!("[FACE] Face tracking completed successfully");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
result.ensure_face_ids();
|
||||||
result.save_to_file(output_path)?;
|
result.save_to_file(output_path)?;
|
||||||
|
|
||||||
tracing::info!(
|
tracing::info!(
|
||||||
@@ -486,6 +501,7 @@ pub async fn process_face(
|
|||||||
tracing::info!("[FACE] Face tracking completed successfully");
|
tracing::info!("[FACE] Face tracking completed successfully");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
result.ensure_face_ids();
|
||||||
result.save_to_file(output_path)?;
|
result.save_to_file(output_path)?;
|
||||||
|
|
||||||
tracing::info!(
|
tracing::info!(
|
||||||
@@ -604,6 +620,7 @@ async fn run_face_with_config(
|
|||||||
serde_json::from_str(&json_str).context("Failed to parse Swift FACE output")?;
|
serde_json::from_str(&json_str).context("Failed to parse Swift FACE output")?;
|
||||||
result.compute_status();
|
result.compute_status();
|
||||||
result.add_metadata("face", "swift_face", uuid);
|
result.add_metadata("face", "swift_face", uuid);
|
||||||
|
result.ensure_face_ids();
|
||||||
result.save_to_file(output_path)?;
|
result.save_to_file(output_path)?;
|
||||||
|
|
||||||
if let Some(uid) = uuid {
|
if let Some(uid) = uuid {
|
||||||
@@ -647,6 +664,7 @@ async fn run_face_with_config(
|
|||||||
.context("Failed to parse Python FACE output")?;
|
.context("Failed to parse Python FACE output")?;
|
||||||
result.compute_status();
|
result.compute_status();
|
||||||
result.add_metadata("face", "python_face_processor", uuid);
|
result.add_metadata("face", "python_face_processor", uuid);
|
||||||
|
result.ensure_face_ids();
|
||||||
result.save_to_file(output_path)?;
|
result.save_to_file(output_path)?;
|
||||||
|
|
||||||
if let Some(uid) = uuid {
|
if let Some(uid) = uuid {
|
||||||
|
|||||||
Reference in New Issue
Block a user