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:
Accusys
2026-08-13 10:12:21 +08:00
parent 71172fa354
commit 39e9ce4c3b
25 changed files with 723 additions and 131 deletions
+38 -2
View File
@@ -96,6 +96,8 @@ struct TraceInfo {
best_face_frame: i64,
best_face_confidence: f64,
best_face_bbox: Option<serde_json::Value>,
avg_capture_quality: f64,
best_face_capture_quality: f64,
sample_face_id: Option<String>,
thumbnail_url: String,
}
@@ -173,6 +175,11 @@ async fn list_traces_sorted(
best_point_id: i64,
best_frame: i64,
best_bbox: Option<serde_json::Value>,
sum_capture_quality: f64,
best_capture_quality: f64,
best_capture_point_id: i64,
best_capture_frame: i64,
best_capture_bbox: Option<serde_json::Value>,
}
let mut trace_data: HashMap<i32, TraceAgg> = HashMap::new();
@@ -181,6 +188,7 @@ async fn list_traces_sorted(
let trace_id = payload["trace_id"].as_i64().unwrap_or(0) as i32;
let frame = payload["frame"].as_i64().unwrap_or(0);
let confidence = payload["confidence"].as_f64().unwrap_or(0.5);
let capture_quality = payload["capture_quality"].as_f64().unwrap_or(0.0);
let point_id = point["id"].as_i64().unwrap_or(0);
if confidence < min_confidence || confidence > max_confidence {
@@ -197,17 +205,29 @@ async fn list_traces_sorted(
best_point_id: 0,
best_frame: 0,
best_bbox: None,
sum_capture_quality: 0.0,
best_capture_quality: 0.0,
best_capture_point_id: 0,
best_capture_frame: 0,
best_capture_bbox: None,
});
entry.face_count += 1;
entry.start_frame = entry.start_frame.min(frame);
entry.end_frame = entry.end_frame.max(frame);
entry.sum_confidence += confidence;
entry.sum_capture_quality += capture_quality;
if confidence > entry.best_confidence {
entry.best_confidence = confidence;
entry.best_point_id = point_id;
entry.best_frame = frame;
entry.best_bbox = payload.get("bbox").cloned();
}
if capture_quality > entry.best_capture_quality {
entry.best_capture_quality = capture_quality;
entry.best_capture_point_id = point_id;
entry.best_capture_frame = frame;
entry.best_capture_bbox = payload.get("bbox").cloned();
}
}
// Filter by min_faces and sort
@@ -222,6 +242,8 @@ async fn list_traces_sorted(
i64,
f64,
Option<serde_json::Value>,
f64,
f64,
)> = trace_data
.into_iter()
.filter(|(_, agg)| agg.face_count >= min_faces)
@@ -232,6 +254,11 @@ async fn list_traces_sorted(
} else {
0.0
};
let avg_cq = if agg.face_count > 0 {
agg.sum_capture_quality / agg.face_count as f64
} else {
0.0
};
(
tid,
agg.face_count,
@@ -243,6 +270,8 @@ async fn list_traces_sorted(
agg.best_frame,
agg.best_confidence,
agg.best_bbox,
avg_cq,
agg.best_capture_quality,
)
})
.collect();
@@ -267,7 +296,7 @@ async fn list_traces_sorted(
let traces: Vec<TraceInfo> = traces_vec
.into_iter()
.map(
|(tid, fc, sf, ef, dur, conf, bfid, bff, bfc, bfb)| TraceInfo {
|(tid, fc, sf, ef, dur, conf, bfid, bff, bfc, bfb, acq, bcq)| TraceInfo {
trace_id: tid,
face_count: fc,
start_frame: sf,
@@ -280,6 +309,8 @@ async fn list_traces_sorted(
best_face_frame: bff,
best_face_confidence: bfc,
best_face_bbox: bfb,
avg_capture_quality: acq,
best_face_capture_quality: bcq,
sample_face_id: None,
thumbnail_url: format!("/api/v1/file/{}/trace/{}/thumbnail", file_uuid, tid),
},
@@ -321,6 +352,7 @@ struct TraceFaceItem {
width: Option<i32>,
height: Option<i32>,
confidence: f64,
capture_quality: f64,
interpolated: bool,
}
@@ -438,6 +470,7 @@ async fn list_trace_faces(
width: Some(mid_w),
height: Some(mid_h),
confidence: 0.0,
capture_quality: 0.0,
interpolated: true,
});
}
@@ -447,6 +480,7 @@ async fn list_trace_faces(
// Add the real detection
let frame_val = frame;
let ft = (frame_val as f64 / fps * 10.0).round() / 10.0;
let capture_quality = payload["capture_quality"].as_f64().unwrap_or(0.0);
faces.push(TraceFaceItem {
id,
start_frame: frame_val,
@@ -458,6 +492,7 @@ async fn list_trace_faces(
width: Some(w),
height: Some(h),
confidence: conf as f64,
capture_quality,
interpolated: false,
});
}
@@ -579,7 +614,8 @@ where
if conf <= 0.7 {
return None;
}
let score = (w as f64 * h as f64) * conf;
let capture_quality = payload["capture_quality"].as_f64().unwrap_or(0.0);
let score = (w as f64 * h as f64) * conf * (0.2 + capture_quality);
Some(Candidate {
frame: payload["frame"].as_i64().unwrap_or(0),
x: bbox["x"].as_f64()? as i32,