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.
This commit is contained in:
@@ -152,6 +152,7 @@ struct SwiftFace: ParsableCommand {
|
|||||||
"bbox": ["x": max(0, faceX), "y": max(0, faceY),
|
"bbox": ["x": max(0, faceX), "y": max(0, faceY),
|
||||||
"width": faceW, "height": faceH],
|
"width": faceW, "height": faceH],
|
||||||
"confidence": Double(lmObs.confidence),
|
"confidence": Double(lmObs.confidence),
|
||||||
|
"captureQuality": Double(lmObs.value(forKey: "faceCaptureQuality") as? Double ?? 0),
|
||||||
]
|
]
|
||||||
|
|
||||||
// Pose from landmark observation
|
// Pose from landmark observation
|
||||||
@@ -219,10 +220,9 @@ struct SwiftFace: ParsableCommand {
|
|||||||
}
|
}
|
||||||
if matched { continue }
|
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 faceObs.confidence < MIN_CONFIDENCE { continue }
|
||||||
if faceConf < MIN_CONFIDENCE { continue }
|
|
||||||
|
|
||||||
let faceW = Int(fBB.size.width * imgW)
|
let faceW = Int(fBB.size.width * imgW)
|
||||||
let faceH = Int(fBB.size.height * imgH)
|
let faceH = Int(fBB.size.height * imgH)
|
||||||
@@ -235,7 +235,8 @@ struct SwiftFace: ParsableCommand {
|
|||||||
var faceData: [String: Any] = [
|
var faceData: [String: Any] = [
|
||||||
"bbox": ["x": max(0, faceX), "y": max(0, faceY),
|
"bbox": ["x": max(0, faceX), "y": max(0, faceY),
|
||||||
"width": faceW, "height": faceH],
|
"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,
|
if let yaw = faceObs.yaw?.doubleValue,
|
||||||
let roll = faceObs.roll?.doubleValue {
|
let roll = faceObs.roll?.doubleValue {
|
||||||
|
|||||||
@@ -171,6 +171,7 @@ func processFrameForFace(pixelBuffer: CVPixelBuffer, fps: Float) -> FrameFaceRes
|
|||||||
"bbox": ["x": max(0, faceX), "y": max(0, faceY),
|
"bbox": ["x": max(0, faceX), "y": max(0, faceY),
|
||||||
"width": faceW, "height": faceH],
|
"width": faceW, "height": faceH],
|
||||||
"confidence": Double(lmObs.confidence),
|
"confidence": Double(lmObs.confidence),
|
||||||
|
"captureQuality": Double(lmObs.value(forKey: "faceCaptureQuality") as? Double ?? 0),
|
||||||
]
|
]
|
||||||
|
|
||||||
if let yaw = lmObs.yaw?.doubleValue,
|
if let yaw = lmObs.yaw?.doubleValue,
|
||||||
@@ -234,8 +235,7 @@ func processFrameForFace(pixelBuffer: CVPixelBuffer, fps: Float) -> FrameFaceRes
|
|||||||
}
|
}
|
||||||
if matched { continue }
|
if matched { continue }
|
||||||
|
|
||||||
let faceConf = Double(faceObs.faceCaptureQuality ?? faceObs.confidence)
|
if faceObs.confidence < MIN_CONFIDENCE { continue }
|
||||||
if faceConf < MIN_CONFIDENCE { continue }
|
|
||||||
|
|
||||||
let faceW = Int(fBB.size.width * imgW)
|
let faceW = Int(fBB.size.width * imgW)
|
||||||
let faceH = Int(fBB.size.height * imgH)
|
let faceH = Int(fBB.size.height * imgH)
|
||||||
@@ -247,7 +247,8 @@ func processFrameForFace(pixelBuffer: CVPixelBuffer, fps: Float) -> FrameFaceRes
|
|||||||
var faceData: [String: Any] = [
|
var faceData: [String: Any] = [
|
||||||
"bbox": ["x": max(0, faceX), "y": max(0, faceY),
|
"bbox": ["x": max(0, faceX), "y": max(0, faceY),
|
||||||
"width": faceW, "height": faceH],
|
"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,
|
if let yaw = faceObs.yaw?.doubleValue,
|
||||||
let roll = faceObs.roll?.doubleValue {
|
let roll = faceObs.roll?.doubleValue {
|
||||||
|
|||||||
Reference in New Issue
Block a user