feat: Face JSON v2 schema - add schema_version, bbox x2/y2/center, keep embeddings, update clustering

This commit is contained in:
Accusys
2026-11-02 14:34:02 +08:00
parent 2fca49b120
commit 5d18183d82
566 changed files with 321788 additions and 1662 deletions
+4 -4
View File
@@ -808,10 +808,10 @@ fn main() {
// Filter low-quality clusters (hand detections, isolated faces)
// Filter criteria:
// - face_count < 20 (too few faces, likely isolated or hand)
// - bbox_area > 150,000 (abnormally large bbox, likely hand/object)
let min_face_count = 20;
let max_bbox_area = 150_000.0;
// - face_count < 5 (too few faces, likely isolated or hand)
// - bbox_area > 200,000 (abnormally large bbox, likely hand/object)
let min_face_count = 3;
let max_bbox_area = 200_000.0;
let mut filtered_cluster_ids: std::collections::HashSet<String> = std::collections::HashSet::new();
let mut filtered_clusters: Vec<Value> = Vec::new();
@@ -48,7 +48,18 @@ struct FacePoint {
struct FaceDetection {
#[serde(skip_serializing_if = "Option::is_none")]
trace_id: Option<i32>,
// FIX: Add flat bbox fields for consistency with face.json
#[serde(default, skip_serializing_if = "Option::is_none")]
x: Option<i32>,
#[serde(default, skip_serializing_if = "Option::is_none")]
y: Option<i32>,
#[serde(default, skip_serializing_if = "Option::is_none")]
width: Option<i32>,
#[serde(default, skip_serializing_if = "Option::is_none")]
height: Option<i32>,
confidence: f32,
// FIX: Make bbox optional during deserialization, will be filled later if missing
#[serde(default)]
bbox: BBox,
#[serde(skip_serializing_if = "Option::is_none")]
embedding: Option<Vec<f32>>,
@@ -62,7 +73,7 @@ struct FaceDetection {
capture_quality: Option<f32>,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
struct BBox {
x: i32,
y: i32,
@@ -171,6 +182,21 @@ fn main() -> Result<()> {
let mut face_data: FaceData = serde_json::from_str(&face_json_str)
.with_context(|| "Failed to parse face.json")?;
// FIX: Ensure all faces have bbox by constructing from flat fields if missing
for frame in &mut face_data.frames {
for face in &mut frame.faces {
if face.bbox.x == 0 && face.bbox.y == 0 && face.bbox.width == 0 && face.bbox.height == 0 {
// bbox is empty, construct from flat fields
face.bbox = BBox {
x: face.x.unwrap_or(0),
y: face.y.unwrap_or(0),
width: face.width.unwrap_or(0),
height: face.height.unwrap_or(0),
};
}
}
}
println!("[TRACE_STORE] Frames: {}", face_data.frames.len());
// Load embeddings from Qdrant
@@ -258,12 +284,24 @@ fn run_face_tracking(
.and_then(|c| c.as_f64())
.unwrap_or(0.9) as f32;
// Qdrant stores x, y, width, height directly (not in bbox object)
let bbox_struct = BBox {
x: point.payload.get("x").and_then(|x| x.as_i64()).unwrap_or(0) as i32,
y: point.payload.get("y").and_then(|y| y.as_i64()).unwrap_or(0) as i32,
width: point.payload.get("width").and_then(|w| w.as_i64()).unwrap_or(0) as i32,
height: point.payload.get("height").and_then(|h| h.as_i64()).unwrap_or(0) as i32,
// Qdrant may store bbox in two formats:
// 1. Nested bbox field (from face_processor.py)
// 2. Direct x, y, width, height fields (from rust_store_traced_faces)
let bbox_struct = if let Some(bbox_obj) = point.payload.get("bbox").and_then(|b| b.as_object()) {
BBox {
x: bbox_obj.get("x").and_then(|x| x.as_i64()).unwrap_or(0) as i32,
y: bbox_obj.get("y").and_then(|y| y.as_i64()).unwrap_or(0) as i32,
width: bbox_obj.get("width").and_then(|w| w.as_i64()).unwrap_or(0) as i32,
height: bbox_obj.get("height").and_then(|h| h.as_i64()).unwrap_or(0) as i32,
}
} else {
// Direct fields
BBox {
x: point.payload.get("x").and_then(|x| x.as_i64()).unwrap_or(0) as i32,
y: point.payload.get("y").and_then(|y| y.as_i64()).unwrap_or(0) as i32,
width: point.payload.get("width").and_then(|w| w.as_i64()).unwrap_or(0) as i32,
height: point.payload.get("height").and_then(|h| h.as_i64()).unwrap_or(0) as i32,
}
};
// Debug: log first few embeddings
@@ -592,10 +630,23 @@ fn update_qdrant_trace_ids(
let payload = point.get("payload").cloned().unwrap_or(Value::Null);
let frame = payload.get("frame").and_then(|f| f.as_i64()).unwrap_or(0);
let x = payload.get("x").and_then(|x| x.as_i64()).unwrap_or(0) as i32;
let y = payload.get("y").and_then(|y| y.as_i64()).unwrap_or(0) as i32;
let width = payload.get("width").and_then(|w| w.as_i64()).unwrap_or(0) as i32;
let height = payload.get("height").and_then(|h| h.as_i64()).unwrap_or(0) as i32;
// Support two bbox formats
let (x, y, width, height) = if let Some(bbox_obj) = payload.get("bbox").and_then(|b| b.as_object()) {
(
bbox_obj.get("x").and_then(|x| x.as_i64()).unwrap_or(0) as i32,
bbox_obj.get("y").and_then(|y| y.as_i64()).unwrap_or(0) as i32,
bbox_obj.get("width").and_then(|w| w.as_i64()).unwrap_or(0) as i32,
bbox_obj.get("height").and_then(|h| h.as_i64()).unwrap_or(0) as i32,
)
} else {
(
payload.get("x").and_then(|x| x.as_i64()).unwrap_or(0) as i32,
payload.get("y").and_then(|y| y.as_i64()).unwrap_or(0) as i32,
payload.get("width").and_then(|w| w.as_i64()).unwrap_or(0) as i32,
payload.get("height").and_then(|h| h.as_i64()).unwrap_or(0) as i32,
)
};
let key = (frame, x, y, width, height);
if let Some(&trace_id) = trace_mapping.get(&key) {