fix: add bbox validation in Swift Face processor

問題:
- Face detection 輸出無效 bbox (width=0, height=0)
- 導致 face tracing 失敗
- 所有 faces trace_id = -1

修復:
- ✅ 添加 bbox 驗證邏輯
- ✅ 過濾 width <= 0 或 height <= 0 的 bbox
- ✅ 添加警告日誌
- ✅ 修復 swift_face_pose.swift 類型錯誤

影響文件:
- scripts/swift_processors/swift_face.swift
- scripts/swift_processors/swift_face_pose.swift

狀態: ✅ 已修復,需要重新處理受影響的文件
This commit is contained in:
Accusys
2026-09-29 01:03:54 +08:00
parent 6b1345bd5a
commit e95cdcc673
2 changed files with 21 additions and 1 deletions
+13
View File
@@ -145,6 +145,12 @@ struct SwiftFace: ParsableCommand {
let faceW = Int(bb.size.width * imgW)
let faceH = Int(bb.size.height * imgH)
// BBox validation - ensure non-zero dimensions
if bb.size.width <= 0 || bb.size.height <= 0 {
print("[WARN] Invalid bbox dimensions (width=\(bb.size.width), height=\(bb.size.height)) at frame \(frameNumber), skipping")
continue
}
// Size filter
if faceW < MIN_SIZE || faceH < MIN_SIZE { continue }
@@ -288,6 +294,13 @@ struct SwiftFace: ParsableCommand {
let faceW = Int(fBB.size.width * imgW)
let faceH = Int(fBB.size.height * imgH)
// BBox validation - ensure non-zero dimensions
if fBB.size.width <= 0 || fBB.size.height <= 0 {
print("[WARN] Invalid bbox dimensions (width=\(fBB.size.width), height=\(fBB.size.height)) at frame \(frameNumber), skipping")
continue
}
if faceW < MIN_SIZE || faceH < MIN_SIZE { continue }
// Unmatched face rect: output without landmarks
@@ -235,10 +235,17 @@ func processFrameForFace(pixelBuffer: CVPixelBuffer, fps: Float) -> FrameFaceRes
}
if matched { continue }
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)
// BBox validation - ensure non-zero dimensions
if fBB.size.width <= 0 || fBB.size.height <= 0 {
print("[WARN] Invalid bbox dimensions (width=\(fBB.size.width), height=\(fBB.size.height)), skipping")
continue
}
if faceW < MIN_SIZE || faceH < MIN_SIZE { continue }
let faceX = Int(fBB.origin.x * imgW)