fix: add min_capture_quality to FaceFilterSettings + trace profile fixes
- Add min_capture_quality to FaceFilterSettings (file_profile.rs) - Fix store_traced_faces.py: load embeddings from Qdrant with_vector=True - Fix face_tracker.py: force new traces when frame_gap > 30 - Fix backfill_trace_profiles.py: key_frame select=eq(n,N), bbox scaling, best_frame - Add best_frame to FaceTraceProfile (Rust + Python) - Fix min_capture_quality persistence in file-profile API
This commit is contained in:
@@ -1728,6 +1728,142 @@ async fn get_appearance_handler(
|
||||
}))
|
||||
}
|
||||
|
||||
// ── Face Landmarks Endpoint ──
|
||||
|
||||
#[derive(Debug, serde::Deserialize)]
|
||||
struct FaceLandmarksQuery {
|
||||
frame: i64,
|
||||
bbox_x: Option<f64>,
|
||||
bbox_y: Option<f64>,
|
||||
bbox_w: Option<f64>,
|
||||
bbox_h: Option<f64>,
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Serialize)]
|
||||
struct FaceBBox {
|
||||
x: i64,
|
||||
y: i64,
|
||||
width: i64,
|
||||
height: i64,
|
||||
confidence: f64,
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Serialize)]
|
||||
struct FaceLandmarksResponse {
|
||||
frame: i64,
|
||||
x: i64,
|
||||
y: i64,
|
||||
width: i64,
|
||||
height: i64,
|
||||
confidence: f64,
|
||||
pose_angle: Option<serde_json::Value>,
|
||||
landmarks: serde_json::Value,
|
||||
lips: serde_json::Value,
|
||||
faces: Vec<FaceBBox>,
|
||||
}
|
||||
|
||||
async fn get_face_landmarks_handler(
|
||||
State(_state): State<crate::api::types::AppState>,
|
||||
Path(file_uuid): Path<String>,
|
||||
Query(params): Query<FaceLandmarksQuery>,
|
||||
) -> Result<axum::Json<FaceLandmarksResponse>, StatusCode> {
|
||||
use crate::core::config::OUTPUT_DIR;
|
||||
|
||||
let output_dir = OUTPUT_DIR.as_str();
|
||||
let face_path = std::path::Path::new(output_dir).join(format!("{}.face.json", file_uuid));
|
||||
|
||||
if !face_path.exists() {
|
||||
tracing::error!("[get_face_landmarks] File not found: {}", face_path.display());
|
||||
return Err(StatusCode::NOT_FOUND);
|
||||
}
|
||||
|
||||
let content = std::fs::read_to_string(&face_path).map_err(|e| {
|
||||
tracing::error!("[get_face_landmarks] Failed to read face.json: {}", e);
|
||||
StatusCode::INTERNAL_SERVER_ERROR
|
||||
})?;
|
||||
|
||||
let data: serde_json::Value = serde_json::from_str(&content).map_err(|e| {
|
||||
tracing::error!("[get_face_landmarks] Failed to parse face.json: {}", e);
|
||||
StatusCode::INTERNAL_SERVER_ERROR
|
||||
})?;
|
||||
|
||||
let frames = data
|
||||
.get("frames")
|
||||
.and_then(|v| v.as_array())
|
||||
.ok_or(StatusCode::NOT_FOUND)?;
|
||||
|
||||
let frame_data = frames
|
||||
.iter()
|
||||
.find(|f| f.get("frame").and_then(|v| v.as_i64()) == Some(params.frame))
|
||||
.ok_or(StatusCode::NOT_FOUND)?;
|
||||
|
||||
let faces = frame_data
|
||||
.get("faces")
|
||||
.and_then(|v| v.as_array())
|
||||
.ok_or(StatusCode::NOT_FOUND)?;
|
||||
|
||||
if faces.is_empty() {
|
||||
return Err(StatusCode::NOT_FOUND);
|
||||
}
|
||||
|
||||
// Select the face closest to the provided bbox center (if given), otherwise the first face.
|
||||
let selected = match (params.bbox_x, params.bbox_y, params.bbox_w, params.bbox_h) {
|
||||
(Some(bx), Some(by), Some(bw), Some(bh)) => {
|
||||
const MAX_CENTER_DIST: f64 = 100.0;
|
||||
let tcx = bx + bw / 2.0;
|
||||
let tcy = by + bh / 2.0;
|
||||
let mut best_dist = f64::MAX;
|
||||
let mut best = None;
|
||||
for face in faces {
|
||||
let x = face.get("x").and_then(|v| v.as_f64()).unwrap_or(0.0);
|
||||
let y = face.get("y").and_then(|v| v.as_f64()).unwrap_or(0.0);
|
||||
let w = face.get("width").and_then(|v| v.as_f64()).unwrap_or(0.0);
|
||||
let h = face.get("height").and_then(|v| v.as_f64()).unwrap_or(0.0);
|
||||
let cx = x + w / 2.0;
|
||||
let cy = y + h / 2.0;
|
||||
let dist = (cx - tcx).abs() + (cy - tcy).abs();
|
||||
if dist < best_dist && dist < MAX_CENTER_DIST {
|
||||
best_dist = dist;
|
||||
best = Some(face);
|
||||
}
|
||||
}
|
||||
best.ok_or(StatusCode::NOT_FOUND)?
|
||||
}
|
||||
_ => &faces[0],
|
||||
};
|
||||
|
||||
// All faces in this frame (bbox + confidence only) for other-face overlays.
|
||||
let faces_out: Vec<FaceBBox> = faces
|
||||
.iter()
|
||||
.map(|face| FaceBBox {
|
||||
x: face.get("x").and_then(|v| v.as_i64()).unwrap_or(0),
|
||||
y: face.get("y").and_then(|v| v.as_i64()).unwrap_or(0),
|
||||
width: face.get("width").and_then(|v| v.as_i64()).unwrap_or(0),
|
||||
height: face.get("height").and_then(|v| v.as_i64()).unwrap_or(0),
|
||||
confidence: face.get("confidence").and_then(|v| v.as_f64()).unwrap_or(0.0),
|
||||
})
|
||||
.collect();
|
||||
|
||||
Ok(axum::Json(FaceLandmarksResponse {
|
||||
frame: params.frame,
|
||||
x: selected.get("x").and_then(|v| v.as_i64()).unwrap_or(0),
|
||||
y: selected.get("y").and_then(|v| v.as_i64()).unwrap_or(0),
|
||||
width: selected.get("width").and_then(|v| v.as_i64()).unwrap_or(0),
|
||||
height: selected.get("height").and_then(|v| v.as_i64()).unwrap_or(0),
|
||||
confidence: selected.get("confidence").and_then(|v| v.as_f64()).unwrap_or(0.0),
|
||||
pose_angle: selected.get("pose_angle").cloned().or_else(|| selected.get("pose").cloned()),
|
||||
landmarks: selected
|
||||
.get("landmarks")
|
||||
.cloned()
|
||||
.unwrap_or(serde_json::Value::Null),
|
||||
lips: selected
|
||||
.get("lips")
|
||||
.cloned()
|
||||
.unwrap_or(serde_json::Value::Null),
|
||||
faces: faces_out,
|
||||
}))
|
||||
}
|
||||
|
||||
pub fn pose_appearance_routes() -> Router<crate::api::types::AppState> {
|
||||
Router::new()
|
||||
.route("/api/v1/file/:file_uuid/pose", get(get_pose_handler))
|
||||
@@ -1735,4 +1871,8 @@ pub fn pose_appearance_routes() -> Router<crate::api::types::AppState> {
|
||||
"/api/v1/file/:file_uuid/appearance",
|
||||
get(get_appearance_handler),
|
||||
)
|
||||
.route(
|
||||
"/api/v1/file/:file_uuid/face-landmarks",
|
||||
get(get_face_landmarks_handler),
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user