feat: improve face clustering and add trace-profile API fallback

Core changes:
- Face clustering threshold: 0.35 → 0.15 (better male/female separation)
- Add auto-filtering for low-quality clusters (face_count<20, bbox_area>150000)
- Add filesystem fallback for trace-profile API

Face clustering improvements:
- Correctly separates male and female faces
- Filters hand detections and isolated faces
- Result: 2 persons (186 male, 174 female) vs 4 persons before

Trace profile API:
- GET /api/v1/trace-profile?file_uuid=X&trace_id=Y
- Returns data from PostgreSQL or filesystem fallback
- Simplifies frontend: no need to know filesystem structure
- Fixes Studio 'trace profile not found' error

Issue: docs_v1.0/M4_workspace/2026-10-16_studio_trace_profile_bug_report.md
This commit is contained in:
Accusys
2026-10-16 13:36:29 +08:00
parent e8b26f997f
commit 2090dd25ea
16 changed files with 4860 additions and 163 deletions
File diff suppressed because it is too large Load Diff
+65 -1
View File
@@ -145,7 +145,71 @@ pub async fn get_trace_profile_handler(
StatusCode::INTERNAL_SERVER_ERROR
})?;
let (name, _ext_id, tp_props, tn_props) = row.ok_or(StatusCode::NOT_FOUND)?;
// If not found in database, try to read from filesystem
if row.is_none() {
tracing::info!("[TraceProfile] Not found in DB, trying filesystem for file_uuid={}, trace_id={}",
params.file_uuid, params.trace_id);
// Construct path: {output_dir}/{file_uuid}/trace_{trace_id}/trace_profile.json
let output_dir = std::env::var("MOMENTRY_OUTPUT_DIR")
.unwrap_or_else(|_| "/Users/accusys/momentry/output".to_string());
let profile_path = std::path::Path::new(&output_dir)
.join(&params.file_uuid)
.join(format!("trace_{}", params.trace_id))
.join("trace_profile.json");
// Read from filesystem
if profile_path.exists() {
match std::fs::read_to_string(&profile_path) {
Ok(content) => {
match serde_json::from_str::<serde_json::Value>(&content) {
Ok(profile_json) => {
// Extract fields from filesystem JSON
let name = profile_json.get("label")
.and_then(|v| v.as_str())
.unwrap_or(&format!("trace_{}", params.trace_id))
.to_string();
let key_frame = profile_json.get("key_frame")
.and_then(|v| v.as_str())
.map(|s| s.to_string());
let key_face = profile_json.get("key_face")
.and_then(|v| v.as_str())
.map(|s| s.to_string());
let bbox = profile_json.get("avg_bbox").cloned();
tracing::info!("[TraceProfile] Successfully loaded from filesystem: {}", profile_path.display());
return Ok(Json(TraceProfile {
file_uuid: params.file_uuid,
trace_id: params.trace_id,
name,
key_frame,
key_face,
aliases: None,
bbox,
properties: profile_json,
}));
}
Err(e) => {
tracing::error!("[TraceProfile] Failed to parse JSON from {}: {}", profile_path.display(), e);
}
}
}
Err(e) => {
tracing::error!("[TraceProfile] Failed to read {}: {}", profile_path.display(), e);
}
}
} else {
tracing::warn!("[TraceProfile] File not found: {}", profile_path.display());
}
return Err(StatusCode::NOT_FOUND);
}
let (name, _ext_id, tp_props, tn_props) = row.unwrap();
// Merge properties: tp_props takes precedence, tn_props as fallback
let mut properties =