From 71172fa354a6f3e09767368a67945d45290f6dba Mon Sep 17 00:00:00 2001 From: Accusys Date: Wed, 12 Aug 2026 11:51:10 +0800 Subject: [PATCH] fix: separate confidence and captureQuality in face detection output Apple Vision provides two distinct scores: - confidence: detection confidence (is this a face?) - faceCaptureQuality: capture quality (is this face suitable for recognition?) Previously these were mixed together as 'confidence'. Now both are stored separately in the output JSON for downstream use. --- scripts/swift_processors/swift_face.swift | 9 +++++---- scripts/swift_processors/swift_face_pose.swift | 7 ++++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/scripts/swift_processors/swift_face.swift b/scripts/swift_processors/swift_face.swift index 47cb8c8c..67a66432 100644 --- a/scripts/swift_processors/swift_face.swift +++ b/scripts/swift_processors/swift_face.swift @@ -152,6 +152,7 @@ struct SwiftFace: ParsableCommand { "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), ] // Pose from landmark observation @@ -219,10 +220,9 @@ struct SwiftFace: ParsableCommand { } if matched { continue } - // Quality filtering for unmatched face rects - uses MIN_CONFIDENCE and MIN_SIZE from outer scope + // Quality filtering for unmatched face rects - let faceConf = Double(faceObs.faceCaptureQuality ?? faceObs.confidence) - if faceConf < MIN_CONFIDENCE { continue } + if faceObs.confidence < MIN_CONFIDENCE { continue } let faceW = Int(fBB.size.width * imgW) let faceH = Int(fBB.size.height * imgH) @@ -235,7 +235,8 @@ struct SwiftFace: ParsableCommand { var faceData: [String: Any] = [ "bbox": ["x": max(0, faceX), "y": max(0, faceY), "width": faceW, "height": faceH], - "confidence": Double(faceObs.faceCaptureQuality ?? faceObs.confidence), + "confidence": Double(faceObs.confidence), + "captureQuality": Double(faceObs.faceCaptureQuality ?? 0), ] if let yaw = faceObs.yaw?.doubleValue, let roll = faceObs.roll?.doubleValue { diff --git a/scripts/swift_processors/swift_face_pose.swift b/scripts/swift_processors/swift_face_pose.swift index 507738ae..3b642e88 100644 --- a/scripts/swift_processors/swift_face_pose.swift +++ b/scripts/swift_processors/swift_face_pose.swift @@ -171,6 +171,7 @@ func processFrameForFace(pixelBuffer: CVPixelBuffer, fps: Float) -> FrameFaceRes "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), ] if let yaw = lmObs.yaw?.doubleValue, @@ -234,8 +235,7 @@ func processFrameForFace(pixelBuffer: CVPixelBuffer, fps: Float) -> FrameFaceRes } if matched { continue } - let faceConf = Double(faceObs.faceCaptureQuality ?? faceObs.confidence) - if faceConf < MIN_CONFIDENCE { continue } + if faceObs.confidence < MIN_CONFIDENCE { continue } let faceW = Int(fBB.size.width * imgW) let faceH = Int(fBB.size.height * imgH) @@ -247,7 +247,8 @@ func processFrameForFace(pixelBuffer: CVPixelBuffer, fps: Float) -> FrameFaceRes var faceData: [String: Any] = [ "bbox": ["x": max(0, faceX), "y": max(0, faceY), "width": faceW, "height": faceH], - "confidence": Double(faceObs.faceCaptureQuality ?? faceObs.confidence), + "confidence": Double(faceObs.confidence), + "captureQuality": Double(faceObs.faceCaptureQuality ?? 0), ] if let yaw = faceObs.yaw?.doubleValue, let roll = faceObs.roll?.doubleValue {