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:
@@ -39,8 +39,9 @@ struct SwiftFace: ParsableCommand {
|
||||
print("[SwiftFace] Video: \(width)x\(height), \(String(format: "%.1f", fps))fps, \(totalFrames) frames")
|
||||
|
||||
// Read face detection settings from environment variables (with defaults)
|
||||
let MIN_CONFIDENCE = Double(ProcessInfo.processInfo.environment["FACE_MIN_CONFIDENCE"] ?? "0.75") ?? 0.75
|
||||
let MIN_SIZE = Int(ProcessInfo.processInfo.environment["FACE_MIN_SIZE"] ?? "64") ?? 64
|
||||
// Keep in sync with src/core/config.rs FACE_MIN_CONFIDENCE_DEFAULT / FACE_MIN_SIZE_DEFAULT
|
||||
let MIN_CONFIDENCE = Double(ProcessInfo.processInfo.environment["FACE_MIN_CONFIDENCE"] ?? "0.5") ?? 0.5
|
||||
let MIN_SIZE = Int(ProcessInfo.processInfo.environment["FACE_MIN_SIZE"] ?? "1") ?? 1
|
||||
print("[SwiftFace] Settings: MIN_CONFIDENCE=\(MIN_CONFIDENCE), MIN_SIZE=\(MIN_SIZE)")
|
||||
|
||||
let generator = AVAssetImageGenerator(asset: asset)
|
||||
@@ -109,15 +110,17 @@ struct SwiftFace: ParsableCommand {
|
||||
let handler = VNImageRequestHandler(cvPixelBuffer: pb, options: [:])
|
||||
let detectReq = VNDetectFaceRectanglesRequest()
|
||||
let lmReq = VNDetectFaceLandmarksRequest()
|
||||
let captureQReq = VNDetectFaceCaptureQualityRequest()
|
||||
|
||||
do {
|
||||
try handler.perform([detectReq, lmReq])
|
||||
try handler.perform([detectReq, lmReq, captureQReq])
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
|
||||
let faceObservations = detectReq.results ?? []
|
||||
let landmarkObservations = lmReq.results ?? []
|
||||
let captureQualityObs = captureQReq.results ?? []
|
||||
guard !faceObservations.isEmpty || !landmarkObservations.isEmpty else {
|
||||
return
|
||||
}
|
||||
@@ -148,11 +151,31 @@ struct SwiftFace: ParsableCommand {
|
||||
let faceX = Int(bb.origin.x * imgW)
|
||||
let faceY = Int((1.0 - bb.origin.y - bb.size.height) * imgH)
|
||||
|
||||
// Match capture quality request by bbox overlap (landmarks request
|
||||
// results don't populate faceCaptureQuality on macOS)
|
||||
var captureQ = 0.0
|
||||
var bestOverlap: CGFloat = 0
|
||||
for cqObs in captureQualityObs {
|
||||
let cb = cqObs.boundingBox
|
||||
let ix = max(bb.minX, cb.minX)
|
||||
let iy = max(bb.minY, cb.minY)
|
||||
let iw = min(bb.maxX, cb.maxX) - ix
|
||||
let ih = min(bb.maxY, cb.maxY) - iy
|
||||
if iw <= 0 || ih <= 0 { continue }
|
||||
let overlap = (iw * ih) / (bb.width * bb.height)
|
||||
if overlap > bestOverlap {
|
||||
bestOverlap = overlap
|
||||
if let cq = cqObs.faceCaptureQuality {
|
||||
captureQ = Double(cq)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var faceData: [String: Any] = [
|
||||
"bbox": ["x": max(0, faceX), "y": max(0, faceY),
|
||||
"width": faceW, "height": faceH],
|
||||
"confidence": Double(lmObs.confidence),
|
||||
"captureQuality": Double(lmObs.value(forKey: "faceCaptureQuality") as? Double ?? 0),
|
||||
"captureQuality": captureQ,
|
||||
]
|
||||
|
||||
// Pose from landmark observation
|
||||
@@ -222,7 +245,7 @@ struct SwiftFace: ParsableCommand {
|
||||
|
||||
// Quality filtering for unmatched face rects
|
||||
|
||||
if faceObs.confidence < MIN_CONFIDENCE { continue }
|
||||
if Double(faceObs.confidence) < MIN_CONFIDENCE { continue }
|
||||
|
||||
let faceW = Int(fBB.size.width * imgW)
|
||||
let faceH = Int(fBB.size.height * imgH)
|
||||
@@ -232,11 +255,30 @@ struct SwiftFace: ParsableCommand {
|
||||
let faceX = Int(fBB.origin.x * imgW)
|
||||
let faceY = Int((1.0 - fBB.origin.y - fBB.size.height) * imgH)
|
||||
|
||||
// Match capture quality request by bbox overlap
|
||||
var captureQ = 0.0
|
||||
var bestOverlap: CGFloat = 0
|
||||
for cqObs in captureQualityObs {
|
||||
let cb = cqObs.boundingBox
|
||||
let ix = max(fBB.minX, cb.minX)
|
||||
let iy = max(fBB.minY, cb.minY)
|
||||
let iw = min(fBB.maxX, cb.maxX) - ix
|
||||
let ih = min(fBB.maxY, cb.maxY) - iy
|
||||
if iw <= 0 || ih <= 0 { continue }
|
||||
let overlap = (iw * ih) / (fBB.width * fBB.height)
|
||||
if overlap > bestOverlap {
|
||||
bestOverlap = overlap
|
||||
if let cq = cqObs.faceCaptureQuality {
|
||||
captureQ = Double(cq)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var faceData: [String: Any] = [
|
||||
"bbox": ["x": max(0, faceX), "y": max(0, faceY),
|
||||
"width": faceW, "height": faceH],
|
||||
"confidence": Double(faceObs.confidence),
|
||||
"captureQuality": Double(faceObs.faceCaptureQuality ?? 0),
|
||||
"captureQuality": captureQ,
|
||||
]
|
||||
if let yaw = faceObs.yaw?.doubleValue,
|
||||
let roll = faceObs.roll?.doubleValue {
|
||||
|
||||
Reference in New Issue
Block a user