react-native-vision-camera-spoof-detector 1.0.26 → 1.0.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- #Thu Sep 03 10:53:58 IST 2026
2
- gradle.version=9.2.0
1
+ #Thu Sep 03 17:04:14 IST 2026
2
+ gradle.version=8.9
@@ -11,9 +11,9 @@ import Accelerate
11
11
  import TensorFlowLite
12
12
  #endif
13
13
 
14
- typealias FaceAntiSpoofFrameType = Frame
15
- typealias FaceAntiSpoofProxyType = VisionCameraProxyHolder
16
- typealias FaceAntiSpoofPluginBase = FrameProcessorPlugin
14
+ typealias FaceAntiSpoofFrameType = VisionCamera.Frame
15
+ typealias FaceAntiSpoofProxyType = VisionCamera.VisionCameraProxyHolder
16
+ typealias FaceAntiSpoofPluginBase = VisionCamera.FrameProcessorPlugin
17
17
 
18
18
  @objc(FaceAntiSpoofFrameProcessor)
19
19
  class FaceAntiSpoofFrameProcessor: FaceAntiSpoofPluginBase {
@@ -24,6 +24,9 @@ class FaceAntiSpoofFrameProcessor: FaceAntiSpoofPluginBase {
24
24
  private var isProcessing: Bool = false
25
25
  private var latestResult: [String: Any] = ["error": "Not initialized", "isLive": false, "label": "Not Initialized"]
26
26
  private static let INPUT_IMAGE_SIZE: Int = 256
27
+ private static let BASE_THRESHOLD: Float = 0.2
28
+ private static let LAPLACE_THRESHOLD: Int = 50
29
+ private static let LAPLACIAN_THRESHOLD: Int = 4000
27
30
 
28
31
  #if canImport(TensorFlowLite)
29
32
  // Interpreter is provided by FaceAntiSpoofManager.sharedInterpreter
@@ -90,7 +93,7 @@ class FaceAntiSpoofFrameProcessor: FaceAntiSpoofPluginBase {
90
93
 
91
94
  // Capture a small, resized RGB float snapshot synchronously while the pixel buffer is valid
92
95
  let targetSize = CGSize(width: Self.INPUT_IMAGE_SIZE, height: Self.INPUT_IMAGE_SIZE)
93
- guard let rgbInput = Self.rgbFloatData(from: pixelBuffer, size: targetSize) else {
96
+ guard let rgbInput = Self.rgbFloatData(from: pixelBuffer, orientation: frame.orientation, size: targetSize) else {
94
97
  objc_sync_enter(self)
95
98
  isProcessing = false
96
99
  objc_sync_exit(self)
@@ -145,14 +148,15 @@ class FaceAntiSpoofFrameProcessor: FaceAntiSpoofPluginBase {
145
148
 
146
149
  let combined = Self.calculateCombinedScore(neuralScore: nnScore, laplacianScore: lapScore)
147
150
  let confidence = Self.calculateConfidence(neuralScore: nnScore, laplacianScore: lapScore)
151
+ let isLive = nnScore < Self.BASE_THRESHOLD && lapScore > Self.LAPLACIAN_THRESHOLD
148
152
 
149
153
  self.latestResult = [
150
154
  "neuralNetworkScore": Double(nnScore),
151
155
  "laplacianScore": lapScore,
152
156
  "combinedScore": Double(combined),
153
157
  "confidence": Double(confidence),
154
- "isLive": combined > 0.5,
155
- "label": combined > 0.5 ? "live" : "spoof",
158
+ "isLive": isLive,
159
+ "label": isLive ? "live" : "spoof",
156
160
  "width": width,
157
161
  "height": height
158
162
  ]
@@ -180,11 +184,25 @@ class FaceAntiSpoofFrameProcessor: FaceAntiSpoofPluginBase {
180
184
 
181
185
  private static let sharedCIContext: CIContext = CIContext(options: nil)
182
186
 
183
- private static func rgbFloatData(from pixelBuffer: CVPixelBuffer, size: CGSize) -> [Float]? {
187
+ private static func rgbFloatData(from pixelBuffer: CVPixelBuffer, orientation: UIImage.Orientation, size: CGSize) -> [Float]? {
184
188
  CVPixelBufferLockBaseAddress(pixelBuffer, CVPixelBufferLockFlags.readOnly)
185
189
  defer { CVPixelBufferUnlockBaseAddress(pixelBuffer, CVPixelBufferLockFlags.readOnly) }
186
190
 
187
- let ciImage = CIImage(cvPixelBuffer: pixelBuffer)
191
+ let image = CIImage(cvPixelBuffer: pixelBuffer)
192
+ let exifOrientation: CGImagePropertyOrientation
193
+ switch orientation {
194
+ case .up, .upMirrored:
195
+ exifOrientation = .up
196
+ case .right, .rightMirrored:
197
+ exifOrientation = .right
198
+ case .down, .downMirrored:
199
+ exifOrientation = .down
200
+ case .left, .leftMirrored:
201
+ exifOrientation = .left
202
+ @unknown default:
203
+ exifOrientation = .up
204
+ }
205
+ let ciImage = image.oriented(forExifOrientation: Int32(exifOrientation.rawValue))
188
206
  let context = Self.sharedCIContext
189
207
  guard let cgImage = context.createCGImage(ciImage, from: ciImage.extent) else { return nil }
190
208
 
@@ -243,7 +261,7 @@ class FaceAntiSpoofFrameProcessor: FaceAntiSpoofPluginBase {
243
261
  let laplace = [[0,1,0],[1,-4,1],[0,1,0]]
244
262
  let size = 3
245
263
  var score = 0
246
- let threshold = 50
264
+ let threshold = Self.LAPLACE_THRESHOLD
247
265
  for y in 0..<(height - size + 1) {
248
266
  for x in 0..<(width - size + 1) {
249
267
  var result = 0
@@ -262,7 +280,7 @@ class FaceAntiSpoofFrameProcessor: FaceAntiSpoofPluginBase {
262
280
 
263
281
  private static func calculateCombinedScore(neuralScore: Float, laplacianScore: Int) -> Float {
264
282
  let normalizedNeural = min(max(neuralScore, 0), 1)
265
- let normalizedLaplacian = min(max(Float(laplacianScore) / 4000.0, 0), 1)
283
+ let normalizedLaplacian = min(max(Float(laplacianScore) / Float(Self.LAPLACIAN_THRESHOLD), 0), 1)
266
284
  let neuralWeight: Float = 0.6
267
285
  let laplacianWeight: Float = 0.4
268
286
  let invertedNeural = 1.0 - normalizedNeural
@@ -271,7 +289,7 @@ class FaceAntiSpoofFrameProcessor: FaceAntiSpoofPluginBase {
271
289
 
272
290
  private static func calculateConfidence(neuralScore: Float, laplacianScore: Int) -> Float {
273
291
  let neuralConfidence = min(max(neuralScore, 0), 1)
274
- let laplacianConfidence = min(max(Float(laplacianScore) / 4000.0, 0), 1)
292
+ let laplacianConfidence = min(max(Float(laplacianScore) / Float(Self.LAPLACIAN_THRESHOLD), 0), 1)
275
293
  let invertedNeural = 1.0 - neuralConfidence
276
294
  return (invertedNeural * 0.6 + laplacianConfidence * 0.4)
277
295
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-vision-camera-spoof-detector",
3
- "version": "1.0.26",
3
+ "version": "1.0.27",
4
4
  "description": "High-performance face anti-spoofing and liveness detection module for React Native Vision Camera. Uses TensorFlow Lite with GPU acceleration and optimized YUV processing.",
5
5
  "homepage": "https://github.com/dpraful/react-native-vision-camera-spoof-detector",
6
6
  "repository": {
@@ -18,5 +18,5 @@ Pod::Spec.new do |s|
18
18
  s.dependency 'VisionCamera'
19
19
 
20
20
  # Keep default deployment target and static linkage consistent with RN
21
- s.pod_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' }
21
+ s.pod_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' }
22
22
  end