react-native-vision-camera-spoof-detector 1.3.4 → 1.3.6

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.
package/README.md CHANGED
@@ -136,7 +136,7 @@ const styles = StyleSheet.create({
136
136
  });
137
137
  ```
138
138
 
139
- The output is processed natively; the hook returns a `CameraOutput` for Vision Camera's `outputs` array. Callbacks are rate-limited by `uiUpdateIntervalMs` (default 100 ms), except that face-count changes can trigger `onFacesDetected` immediately. `onStableFaceDetected` fires once when its face-stability and liveness gates pass; reset it with `resetFaceAntiSpoofFrameOutput` to allow another stable-face callback.
139
+ The output is processed natively; the hook returns a `CameraOutput` for Vision Camera's `outputs` array. `onResult` and `onFacesDetected` are called for every processed frame. `onStableFaceDetected` fires once when its face-stability and liveness gates pass; reset it with `resetFaceAntiSpoofFrameOutput` to allow another stable-face callback.
140
140
 
141
141
  ## API reference
142
142
 
@@ -161,13 +161,11 @@ Options:
161
161
 
162
162
  ```ts
163
163
  interface UseFaceAntiSpoofFrameOutputOptions {
164
- targetResolution?: { width: number; height: number };
165
164
  antispoofLevel?: number;
166
165
  stableFrames?: number;
167
166
  requiredLiveFrames?: number;
168
167
  laplacianThreshold?: number;
169
168
  maxNeuralSpoofScore?: number;
170
- uiUpdateIntervalMs?: number;
171
169
  onFacesDetected?: (faces: SpoofDetectedFace[]) => void;
172
170
  onResult?: (result: FaceAntiSpoofingResult) => void;
173
171
  onStableFaceDetected?: (face: SpoofDetectedFace['bounds'], result: FaceAntiSpoofingResult) => void;
@@ -195,10 +193,8 @@ Default output options on both platforms:
195
193
  | `requiredLiveFrames` | `3` | Consecutive score-passing frames required before notification |
196
194
  | `laplacianThreshold` | `1100` | Minimum Laplacian score for a frame to pass |
197
195
  | `maxNeuralSpoofScore` | `0.1` | Neural scores at or above this value fail the liveness gate |
198
- | `uiUpdateIntervalMs` | `100` | Minimum interval between score/face updates when the eligible face count is unchanged |
199
- | `targetResolution` | Camera-selected | Optional requested analysis resolution |
200
196
 
201
- On Android devices identified by the system as low-RAM, and on iOS devices with 4 GB physical memory or less, a requested resolution wider than 640 pixels is scaled down proportionally. With no `targetResolution`, the camera selects the analysis resolution. Android uses YUV frames and ML Kit; iOS uses BGRA frames and Vision. Platform model runtimes and score calculations may differ, so calibrate thresholds on representative devices and presentation-attack data rather than assuming identical score distributions.
197
+ Vision Camera selects the analysis resolution. Android uses YUV frames and ML Kit; iOS uses BGRA frames and Vision. Platform model runtimes and score calculations may differ, so calibrate thresholds on representative devices and presentation-attack data rather than assuming identical score distributions.
202
198
 
203
199
  The brightness and Laplacian checks are image-quality gates, not independent proof of liveness. Threshold defaults are starting points, not validated biometric security thresholds. Evaluate the complete capture flow against bona fide and attack presentations before relying on it in production.
204
200
 
@@ -251,14 +247,14 @@ Result fields:
251
247
  - Uses CameraX `ImageAnalysis`, ML Kit face detection, and the bundled TensorFlow Lite model
252
248
  - Prefers GPU inference, falls back to NNAPI, then CPU
253
249
  - Uses YUV input, a brightness gate, face-size/frame-margin/pose/landmark checks, and a padded, eye-aligned face crop
254
- - Uses `MirrorMode.AUTO` and applies a requested analysis resolution when provided
250
+ - Uses `MirrorMode.AUTO` and Vision Camera's selected analysis resolution
255
251
 
256
252
  ### iOS
257
253
 
258
254
  - Uses `AVCaptureVideoDataOutput`, Apple Vision face/landmark detection, and the bundled TensorFlow Lite model
259
255
  - Uses Metal when available, with CPU fallback
260
256
  - Uses BGRA input, a brightness gate, face-size/frame-margin/pose/landmark checks, and a padded, eye-aligned face crop
261
- - Automatically adjusts video mirroring and only constrains resolution when `targetResolution` is provided
257
+ - Automatically adjusts video mirroring and uses Vision Camera's selected analysis resolution
262
258
 
263
259
  ## Troubleshooting
264
260
 
@@ -3,15 +3,10 @@ package com.margelo.nitro.camera.spoofdetector
3
3
  import android.graphics.Matrix
4
4
  import android.graphics.PointF
5
5
  import android.graphics.RectF
6
- import android.os.SystemClock
7
- import android.app.ActivityManager
8
- import android.content.Context
9
6
  import androidx.annotation.OptIn
10
7
  import androidx.camera.core.ExperimentalGetImage
11
8
  import androidx.camera.core.ImageAnalysis
12
9
  import androidx.camera.core.ImageProxy
13
- import androidx.camera.core.resolutionselector.ResolutionSelector
14
- import androidx.camera.core.resolutionselector.ResolutionStrategy
15
10
  import com.google.android.gms.tasks.Task
16
11
  import com.google.android.gms.tasks.Tasks
17
12
  import com.google.mlkit.vision.common.InputImage
@@ -69,20 +64,11 @@ class HybridSpoofDetectorOutput(
69
64
  private val requiredLiveFrames = (options.requiredLiveFrames ?: 3.0).toInt().coerceAtLeast(1)
70
65
  private val laplacianThreshold = options.laplacianThreshold ?: 1100.0
71
66
  private val maxNeuralSpoofScore = options.maxNeuralSpoofScore ?: 0.1
72
- private val uiUpdateIntervalMs = (options.uiUpdateIntervalMs ?: 100.0).toLong().coerceAtLeast(0L)
73
- private val isLowRamDevice by lazy {
74
- val context = NitroModules.applicationContext
75
- val activityManager = context?.getSystemService(Context.ACTIVITY_SERVICE) as? ActivityManager
76
- activityManager?.isLowRamDevice == true
77
- }
78
67
  private var captured = false
79
68
  private var stableCount = 0
80
69
  private var lastFaceBounds: SpoofDetectedFaceBounds? = null
81
70
  private var consecutiveLiveFrames = 0
82
71
  private var lastSpoofResult: AntiSpoofingResult? = null
83
- private var lastFaceCount = -1
84
- private var lastFacesUpdateAtMs = 0L
85
- private var lastResultUpdateAtMs = 0L
86
72
  private var imageAnalysis: ImageAnalysis? = null
87
73
  private companion object {
88
74
  private const val MIN_FACE_WIDTH_RATIO = 0.18f
@@ -97,32 +83,12 @@ class HybridSpoofDetectorOutput(
97
83
  mirrorMode: MirrorMode,
98
84
  config: NativeCameraOutput.Config,
99
85
  ): NativeCameraOutput.PreparedUseCase {
100
- val requestedTarget = options.targetResolution
101
- val target = requestedTarget?.let {
102
- if (isLowRamDevice && it.width > 640.0) {
103
- val scale = 640.0 / it.width
104
- android.util.Size(640, (it.height * scale).toInt().coerceAtLeast(1))
105
- } else {
106
- android.util.Size(it.width.toInt(), it.height.toInt())
107
- }
108
- }
109
- val selector = target?.let {
110
- ResolutionSelector.Builder()
111
- .setResolutionStrategy(
112
- ResolutionStrategy(
113
- it,
114
- ResolutionStrategy.FALLBACK_RULE_CLOSEST_HIGHER_THEN_LOWER,
115
- )
116
- )
117
- .build()
118
- }
119
86
  val analysis = ImageAnalysis.Builder()
120
87
  .setOutputImageFormat(ImageAnalysis.OUTPUT_IMAGE_FORMAT_YUV_420_888)
121
88
  .setTargetRotation(outputOrientation.surfaceRotation)
122
89
  .setOutputImageRotationEnabled(false)
123
90
  .setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST)
124
91
  .setAllowDroppingLateFrames(true)
125
- .apply { if (selector != null) setResolutionSelector(selector) }
126
92
  .build()
127
93
  return NativeCameraOutput.PreparedUseCase(analysis) {
128
94
  imageAnalysis = analysis
@@ -209,9 +175,6 @@ class HybridSpoofDetectorOutput(
209
175
  .filter { it.isFullFace(frameWidth, frameHeight) }
210
176
  .map { it.toSpoofDetectedFace(transform) }
211
177
  .toTypedArray()
212
- val now = SystemClock.elapsedRealtime()
213
- var shouldNotify = false
214
-
215
178
  synchronized(stateLock) {
216
179
  if (detectedFaces.size == 1) {
217
180
  val bounds = detectedFaces[0].bounds
@@ -225,20 +188,12 @@ class HybridSpoofDetectorOutput(
225
188
  lastSpoofResult = null
226
189
  }
227
190
 
228
- shouldNotify = detectedFaces.size != lastFaceCount ||
229
- now - lastFacesUpdateAtMs >= uiUpdateIntervalMs
230
- if (shouldNotify) {
231
- lastFaceCount = detectedFaces.size
232
- lastFacesUpdateAtMs = now
233
- }
234
191
  }
235
192
 
236
- if (shouldNotify) options.onFacesDetected?.invoke(detectedFaces)
193
+ options.onFacesDetected?.invoke(detectedFaces)
237
194
  }
238
195
 
239
196
  private fun processAntiSpoofResult(result: AntiSpoofingResult) {
240
- val now = SystemClock.elapsedRealtime()
241
- var shouldNotify = false
242
197
  var capture: Pair<SpoofDetectedFaceBounds, AntiSpoofingResult>? = null
243
198
 
244
199
  synchronized(stateLock) {
@@ -257,12 +212,10 @@ class HybridSpoofDetectorOutput(
257
212
  }
258
213
  }
259
214
 
260
- shouldNotify = now - lastResultUpdateAtMs >= uiUpdateIntervalMs
261
- if (shouldNotify) lastResultUpdateAtMs = now
262
215
  capture = readyToCaptureLocked()
263
216
  }
264
217
 
265
- if (shouldNotify) options.onResult.invoke(result)
218
+ options.onResult.invoke(result)
266
219
  capture?.let { (bounds, capturedResult) ->
267
220
  options.onStableFaceDetected?.invoke(bounds, capturedResult)
268
221
  }
@@ -293,9 +246,6 @@ class HybridSpoofDetectorOutput(
293
246
  lastFaceBounds = null
294
247
  consecutiveLiveFrames = 0
295
248
  lastSpoofResult = null
296
- lastFaceCount = -1
297
- lastFacesUpdateAtMs = 0L
298
- lastResultUpdateAtMs = 0L
299
249
  }
300
250
  }
301
251
 
package/index.d.ts CHANGED
@@ -278,7 +278,6 @@ export interface UseFaceAntiSpoofFrameOutputOptions extends Partial<FrameOutputO
278
278
  requiredLiveFrames?: number;
279
279
  laplacianThreshold?: number;
280
280
  maxNeuralSpoofScore?: number;
281
- uiUpdateIntervalMs?: number;
282
281
  onResult?: (result: FaceAntiSpoofingResult) => void;
283
282
  onFacesDetected?: (faces: SpoofDetectedFace[]) => void;
284
283
  onStableFaceDetected?: (face: FaceRect, result: FaceAntiSpoofingResult) => void;
package/index.js CHANGED
@@ -34,13 +34,11 @@ export const useFaceAntiSpoofFrameOutput = ({
34
34
  );
35
35
  return useMemo(
36
36
  () => factory.createSpoofDetectorOutput({
37
- targetResolution: options.targetResolution,
38
37
  antispoofLevel: options.antispoofLevel,
39
38
  stableFrames: options.stableFrames,
40
39
  requiredLiveFrames: options.requiredLiveFrames,
41
40
  laplacianThreshold: options.laplacianThreshold,
42
41
  maxNeuralSpoofScore: options.maxNeuralSpoofScore,
43
- uiUpdateIntervalMs: options.uiUpdateIntervalMs,
44
42
  onResult(result) {
45
43
  resultRef.current?.(result);
46
44
  },
@@ -56,13 +54,11 @@ export const useFaceAntiSpoofFrameOutput = ({
56
54
  }),
57
55
  [
58
56
  factory,
59
- options.targetResolution,
60
57
  options.antispoofLevel,
61
58
  options.stableFrames,
62
59
  options.requiredLiveFrames,
63
60
  options.laplacianThreshold,
64
61
  options.maxNeuralSpoofScore,
65
- options.uiUpdateIntervalMs,
66
62
  hasFaceCallback,
67
63
  hasStableFaceCallback,
68
64
  ],
@@ -25,20 +25,12 @@ final class HybridSpoofDetectorOutput: HybridCameraOutputSpec, NativeCameraOutpu
25
25
  private var lastFaceBounds: SpoofDetectedFaceBounds?
26
26
  private var consecutiveLiveFrames = 0
27
27
  private var lastSpoofResult: AntiSpoofingResult?
28
- private var lastFaceCount = -1
29
- private var lastFacesUpdateAt = 0.0
30
- private var lastResultUpdateAt = 0.0
31
28
 
32
29
  private var antispoofLevel: Double { options.antispoofLevel ?? 0.4 }
33
30
  private var stableFrames: Int { max(1, Int(options.stableFrames ?? 3)) }
34
31
  private var requiredLiveFrames: Int { max(1, Int(options.requiredLiveFrames ?? 3)) }
35
32
  private var laplacianThreshold: Double { options.laplacianThreshold ?? 1100 }
36
33
  private var maxNeuralSpoofScore: Double { options.maxNeuralSpoofScore ?? 0.1 }
37
- private var uiUpdateInterval: Double { max(0, options.uiUpdateIntervalMs ?? 100) / 1000 }
38
- private var isLowMemoryDevice: Bool {
39
- ProcessInfo.processInfo.physicalMemory <= 4 * 1024 * 1024 * 1024
40
- }
41
-
42
34
  let output = AVCaptureVideoDataOutput()
43
35
  let requiresAudioInput = false
44
36
  let requiresDepthFormat = false
@@ -52,24 +44,7 @@ final class HybridSpoofDetectorOutput: HybridCameraOutputSpec, NativeCameraOutpu
52
44
  }
53
45
 
54
46
  var targetResolution: ResolutionRule {
55
- guard let requestedSize = options.targetResolution else {
56
- return .any
57
- }
58
- let requestedResolution = margelo.nitro.camera.Size(
59
- width: requestedSize.width,
60
- height: requestedSize.height
61
- )
62
- let resolution: margelo.nitro.camera.Size
63
- if isLowMemoryDevice && requestedResolution.width > 640 {
64
- let scale = 640 / requestedResolution.width
65
- resolution = margelo.nitro.camera.Size(
66
- width: 640,
67
- height: max(1, (requestedResolution.height * scale).rounded())
68
- )
69
- } else {
70
- resolution = requestedResolution
71
- }
72
- return .closestTo(resolution)
47
+ return .any
73
48
  }
74
49
 
75
50
  init(options: SpoofDetectorOutputOptions) {
@@ -226,7 +201,6 @@ final class HybridSpoofDetectorOutput: HybridCameraOutputSpec, NativeCameraOutpu
226
201
  }
227
202
 
228
203
  private func processDetectedFaces(_ faces: [SpoofDetectedFace]) {
229
- let now = ProcessInfo.processInfo.systemUptime
230
204
  if faces.count == 1 {
231
205
  let bounds = faces[0].bounds
232
206
  stableCount += 1
@@ -239,12 +213,7 @@ final class HybridSpoofDetectorOutput: HybridCameraOutputSpec, NativeCameraOutpu
239
213
  lastSpoofResult = nil
240
214
  }
241
215
 
242
- let shouldNotify = faces.count != lastFaceCount || now - lastFacesUpdateAt >= uiUpdateInterval
243
- if shouldNotify {
244
- lastFaceCount = faces.count
245
- lastFacesUpdateAt = now
246
- options.onFacesDetected?(faces)
247
- }
216
+ options.onFacesDetected?(faces)
248
217
  }
249
218
 
250
219
  private func processAntiSpoofResult(_ result: AntiSpoofingResult) {
@@ -261,11 +230,7 @@ final class HybridSpoofDetectorOutput: HybridCameraOutputSpec, NativeCameraOutpu
261
230
  }
262
231
  }
263
232
 
264
- let now = ProcessInfo.processInfo.systemUptime
265
- if now - lastResultUpdateAt >= uiUpdateInterval {
266
- lastResultUpdateAt = now
267
- options.onResult(result)
268
- }
233
+ options.onResult(result)
269
234
  notifyStableFaceIfReady()
270
235
  }
271
236
 
@@ -16,10 +16,8 @@
16
16
  #include "JFunc_void_SpoofDetectedFaceBounds_AntiSpoofingResult.hpp"
17
17
  #include "JFunc_void_std__exception_ptr.hpp"
18
18
  #include "JFunc_void_std__vector_SpoofDetectedFace_.hpp"
19
- #include "JSize.hpp"
20
19
  #include "JSpoofDetectedFace.hpp"
21
20
  #include "JSpoofDetectedFaceBounds.hpp"
22
- #include "Size.hpp"
23
21
  #include "SpoofDetectedFace.hpp"
24
22
  #include "SpoofDetectedFaceBounds.hpp"
25
23
  #include <NitroModules/JNICallable.hpp>
@@ -48,8 +46,6 @@ namespace margelo::nitro::camera::spoofdetector {
48
46
  [[nodiscard]]
49
47
  SpoofDetectorOutputOptions toCpp() const {
50
48
  static const auto clazz = javaClassStatic();
51
- static const auto fieldTargetResolution = clazz->getField<JSize>("targetResolution");
52
- jni::local_ref<JSize> targetResolution = this->getFieldValue(fieldTargetResolution);
53
49
  static const auto fieldAntispoofLevel = clazz->getField<jni::JDouble>("antispoofLevel");
54
50
  jni::local_ref<jni::JDouble> antispoofLevel = this->getFieldValue(fieldAntispoofLevel);
55
51
  static const auto fieldStableFrames = clazz->getField<jni::JDouble>("stableFrames");
@@ -60,8 +56,6 @@ namespace margelo::nitro::camera::spoofdetector {
60
56
  jni::local_ref<jni::JDouble> laplacianThreshold = this->getFieldValue(fieldLaplacianThreshold);
61
57
  static const auto fieldMaxNeuralSpoofScore = clazz->getField<jni::JDouble>("maxNeuralSpoofScore");
62
58
  jni::local_ref<jni::JDouble> maxNeuralSpoofScore = this->getFieldValue(fieldMaxNeuralSpoofScore);
63
- static const auto fieldUiUpdateIntervalMs = clazz->getField<jni::JDouble>("uiUpdateIntervalMs");
64
- jni::local_ref<jni::JDouble> uiUpdateIntervalMs = this->getFieldValue(fieldUiUpdateIntervalMs);
65
59
  static const auto fieldOnResult = clazz->getField<JFunc_void_AntiSpoofingResult::javaobject>("onResult");
66
60
  jni::local_ref<JFunc_void_AntiSpoofingResult::javaobject> onResult = this->getFieldValue(fieldOnResult);
67
61
  static const auto fieldOnFacesDetected = clazz->getField<JFunc_void_std__vector_SpoofDetectedFace_::javaobject>("onFacesDetected");
@@ -71,13 +65,11 @@ namespace margelo::nitro::camera::spoofdetector {
71
65
  static const auto fieldOnError = clazz->getField<JFunc_void_std__exception_ptr::javaobject>("onError");
72
66
  jni::local_ref<JFunc_void_std__exception_ptr::javaobject> onError = this->getFieldValue(fieldOnError);
73
67
  return SpoofDetectorOutputOptions(
74
- targetResolution != nullptr ? std::make_optional(targetResolution->toCpp()) : std::nullopt,
75
68
  antispoofLevel != nullptr ? std::make_optional(antispoofLevel->value()) : std::nullopt,
76
69
  stableFrames != nullptr ? std::make_optional(stableFrames->value()) : std::nullopt,
77
70
  requiredLiveFrames != nullptr ? std::make_optional(requiredLiveFrames->value()) : std::nullopt,
78
71
  laplacianThreshold != nullptr ? std::make_optional(laplacianThreshold->value()) : std::nullopt,
79
72
  maxNeuralSpoofScore != nullptr ? std::make_optional(maxNeuralSpoofScore->value()) : std::nullopt,
80
- uiUpdateIntervalMs != nullptr ? std::make_optional(uiUpdateIntervalMs->value()) : std::nullopt,
81
73
  [&]() -> std::function<void(const AntiSpoofingResult& /* result */)> {
82
74
  if (onResult->isInstanceOf(JFunc_void_AntiSpoofingResult_cxx::javaClassStatic())) [[likely]] {
83
75
  auto downcast = jni::static_ref_cast<JFunc_void_AntiSpoofingResult_cxx::javaobject>(onResult);
@@ -123,18 +115,16 @@ namespace margelo::nitro::camera::spoofdetector {
123
115
  */
124
116
  [[maybe_unused]]
125
117
  static jni::local_ref<JSpoofDetectorOutputOptions::javaobject> fromCpp(const SpoofDetectorOutputOptions& value) {
126
- using JSignature = JSpoofDetectorOutputOptions(jni::alias_ref<JSize>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<JFunc_void_AntiSpoofingResult::javaobject>, jni::alias_ref<JFunc_void_std__vector_SpoofDetectedFace_::javaobject>, jni::alias_ref<JFunc_void_SpoofDetectedFaceBounds_AntiSpoofingResult::javaobject>, jni::alias_ref<JFunc_void_std__exception_ptr::javaobject>);
118
+ using JSignature = JSpoofDetectorOutputOptions(jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<JFunc_void_AntiSpoofingResult::javaobject>, jni::alias_ref<JFunc_void_std__vector_SpoofDetectedFace_::javaobject>, jni::alias_ref<JFunc_void_SpoofDetectedFaceBounds_AntiSpoofingResult::javaobject>, jni::alias_ref<JFunc_void_std__exception_ptr::javaobject>);
127
119
  static const auto clazz = javaClassStatic();
128
120
  static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
129
121
  return create(
130
122
  clazz,
131
- value.targetResolution.has_value() ? JSize::fromCpp(value.targetResolution.value()) : nullptr,
132
123
  value.antispoofLevel.has_value() ? jni::JDouble::valueOf(value.antispoofLevel.value()) : nullptr,
133
124
  value.stableFrames.has_value() ? jni::JDouble::valueOf(value.stableFrames.value()) : nullptr,
134
125
  value.requiredLiveFrames.has_value() ? jni::JDouble::valueOf(value.requiredLiveFrames.value()) : nullptr,
135
126
  value.laplacianThreshold.has_value() ? jni::JDouble::valueOf(value.laplacianThreshold.value()) : nullptr,
136
127
  value.maxNeuralSpoofScore.has_value() ? jni::JDouble::valueOf(value.maxNeuralSpoofScore.value()) : nullptr,
137
- value.uiUpdateIntervalMs.has_value() ? jni::JDouble::valueOf(value.uiUpdateIntervalMs.value()) : nullptr,
138
128
  JFunc_void_AntiSpoofingResult_cxx::fromCpp(value.onResult),
139
129
  value.onFacesDetected.has_value() ? JFunc_void_std__vector_SpoofDetectedFace__cxx::fromCpp(value.onFacesDetected.value()) : nullptr,
140
130
  value.onStableFaceDetected.has_value() ? JFunc_void_SpoofDetectedFaceBounds_AntiSpoofingResult_cxx::fromCpp(value.onStableFaceDetected.value()) : nullptr,
@@ -18,9 +18,6 @@ import java.util.Objects
18
18
  @DoNotStrip
19
19
  @Keep
20
20
  data class SpoofDetectorOutputOptions(
21
- @DoNotStrip
22
- @Keep
23
- val targetResolution: Size?,
24
21
  @DoNotStrip
25
22
  @Keep
26
23
  val antispoofLevel: Double?,
@@ -38,9 +35,6 @@ data class SpoofDetectorOutputOptions(
38
35
  val maxNeuralSpoofScore: Double?,
39
36
  @DoNotStrip
40
37
  @Keep
41
- val uiUpdateIntervalMs: Double?,
42
- @DoNotStrip
43
- @Keep
44
38
  val onResult: Func_void_AntiSpoofingResult,
45
39
  @DoNotStrip
46
40
  @Keep
@@ -55,19 +49,17 @@ data class SpoofDetectorOutputOptions(
55
49
  /**
56
50
  * Create a new instance of SpoofDetectorOutputOptions from Kotlin
57
51
  */
58
- constructor(targetResolution: Size?, antispoofLevel: Double?, stableFrames: Double?, requiredLiveFrames: Double?, laplacianThreshold: Double?, maxNeuralSpoofScore: Double?, uiUpdateIntervalMs: Double?, onResult: (result: AntiSpoofingResult) -> Unit, onFacesDetected: ((faces: Array<SpoofDetectedFace>) -> Unit)?, onStableFaceDetected: ((face: SpoofDetectedFaceBounds, result: AntiSpoofingResult) -> Unit)?, onError: ((error: Throwable) -> Unit)?):
59
- this(targetResolution, antispoofLevel, stableFrames, requiredLiveFrames, laplacianThreshold, maxNeuralSpoofScore, uiUpdateIntervalMs, Func_void_AntiSpoofingResult_java(onResult), onFacesDetected?.let { Func_void_std__vector_SpoofDetectedFace__java(it) }, onStableFaceDetected?.let { Func_void_SpoofDetectedFaceBounds_AntiSpoofingResult_java(it) }, onError?.let { Func_void_std__exception_ptr_java(it) })
52
+ constructor(antispoofLevel: Double?, stableFrames: Double?, requiredLiveFrames: Double?, laplacianThreshold: Double?, maxNeuralSpoofScore: Double?, onResult: (result: AntiSpoofingResult) -> Unit, onFacesDetected: ((faces: Array<SpoofDetectedFace>) -> Unit)?, onStableFaceDetected: ((face: SpoofDetectedFaceBounds, result: AntiSpoofingResult) -> Unit)?, onError: ((error: Throwable) -> Unit)?):
53
+ this(antispoofLevel, stableFrames, requiredLiveFrames, laplacianThreshold, maxNeuralSpoofScore, Func_void_AntiSpoofingResult_java(onResult), onFacesDetected?.let { Func_void_std__vector_SpoofDetectedFace__java(it) }, onStableFaceDetected?.let { Func_void_SpoofDetectedFaceBounds_AntiSpoofingResult_java(it) }, onError?.let { Func_void_std__exception_ptr_java(it) })
60
54
 
61
55
  override fun equals(other: Any?): Boolean {
62
56
  if (this === other) return true
63
57
  if (other !is SpoofDetectorOutputOptions) return false
64
- return Objects.deepEquals(this.targetResolution, other.targetResolution)
65
- && Objects.deepEquals(this.antispoofLevel, other.antispoofLevel)
58
+ return Objects.deepEquals(this.antispoofLevel, other.antispoofLevel)
66
59
  && Objects.deepEquals(this.stableFrames, other.stableFrames)
67
60
  && Objects.deepEquals(this.requiredLiveFrames, other.requiredLiveFrames)
68
61
  && Objects.deepEquals(this.laplacianThreshold, other.laplacianThreshold)
69
62
  && Objects.deepEquals(this.maxNeuralSpoofScore, other.maxNeuralSpoofScore)
70
- && Objects.deepEquals(this.uiUpdateIntervalMs, other.uiUpdateIntervalMs)
71
63
  && Objects.deepEquals(this.onResult, other.onResult)
72
64
  && Objects.deepEquals(this.onFacesDetected, other.onFacesDetected)
73
65
  && Objects.deepEquals(this.onStableFaceDetected, other.onStableFaceDetected)
@@ -76,13 +68,11 @@ data class SpoofDetectorOutputOptions(
76
68
 
77
69
  override fun hashCode(): Int {
78
70
  return arrayOf<Any?>(
79
- targetResolution,
80
71
  antispoofLevel,
81
72
  stableFrames,
82
73
  requiredLiveFrames,
83
74
  laplacianThreshold,
84
75
  maxNeuralSpoofScore,
85
- uiUpdateIntervalMs,
86
76
  onResult,
87
77
  onFacesDetected,
88
78
  onStableFaceDetected,
@@ -98,8 +88,8 @@ data class SpoofDetectorOutputOptions(
98
88
  @Keep
99
89
  @Suppress("unused")
100
90
  @JvmStatic
101
- private fun fromCpp(targetResolution: Size?, antispoofLevel: Double?, stableFrames: Double?, requiredLiveFrames: Double?, laplacianThreshold: Double?, maxNeuralSpoofScore: Double?, uiUpdateIntervalMs: Double?, onResult: Func_void_AntiSpoofingResult, onFacesDetected: Func_void_std__vector_SpoofDetectedFace_?, onStableFaceDetected: Func_void_SpoofDetectedFaceBounds_AntiSpoofingResult?, onError: Func_void_std__exception_ptr?): SpoofDetectorOutputOptions {
102
- return SpoofDetectorOutputOptions(targetResolution, antispoofLevel, stableFrames, requiredLiveFrames, laplacianThreshold, maxNeuralSpoofScore, uiUpdateIntervalMs, onResult, onFacesDetected, onStableFaceDetected, onError)
91
+ private fun fromCpp(antispoofLevel: Double?, stableFrames: Double?, requiredLiveFrames: Double?, laplacianThreshold: Double?, maxNeuralSpoofScore: Double?, onResult: Func_void_AntiSpoofingResult, onFacesDetected: Func_void_std__vector_SpoofDetectedFace_?, onStableFaceDetected: Func_void_SpoofDetectedFaceBounds_AntiSpoofingResult?, onError: Func_void_std__exception_ptr?): SpoofDetectorOutputOptions {
92
+ return SpoofDetectorOutputOptions(antispoofLevel, stableFrames, requiredLiveFrames, laplacianThreshold, maxNeuralSpoofScore, onResult, onFacesDetected, onStableFaceDetected, onError)
103
93
  }
104
94
  }
105
95
  }
@@ -18,14 +18,8 @@ public extension SpoofDetectorOutputOptions {
18
18
  /**
19
19
  * Create a new instance of `SpoofDetectorOutputOptions`.
20
20
  */
21
- init(targetResolution: Size?, antispoofLevel: Double?, stableFrames: Double?, requiredLiveFrames: Double?, laplacianThreshold: Double?, maxNeuralSpoofScore: Double?, uiUpdateIntervalMs: Double?, onResult: @escaping (_ result: AntiSpoofingResult) -> Void, onFacesDetected: ((_ faces: [SpoofDetectedFace]) -> Void)?, onStableFaceDetected: ((_ face: SpoofDetectedFaceBounds, _ result: AntiSpoofingResult) -> Void)?, onError: ((_ error: Error) -> Void)?) {
22
- self.init({ () -> bridge.std__optional_Size_ in
23
- if let __unwrappedValue = targetResolution {
24
- return bridge.create_std__optional_Size_(__unwrappedValue)
25
- } else {
26
- return .init()
27
- }
28
- }(), { () -> bridge.std__optional_double_ in
21
+ init(antispoofLevel: Double?, stableFrames: Double?, requiredLiveFrames: Double?, laplacianThreshold: Double?, maxNeuralSpoofScore: Double?, onResult: @escaping (_ result: AntiSpoofingResult) -> Void, onFacesDetected: ((_ faces: [SpoofDetectedFace]) -> Void)?, onStableFaceDetected: ((_ face: SpoofDetectedFaceBounds, _ result: AntiSpoofingResult) -> Void)?, onError: ((_ error: Error) -> Void)?) {
22
+ self.init({ () -> bridge.std__optional_double_ in
29
23
  if let __unwrappedValue = antispoofLevel {
30
24
  return bridge.create_std__optional_double_(__unwrappedValue)
31
25
  } else {
@@ -55,12 +49,6 @@ public extension SpoofDetectorOutputOptions {
55
49
  } else {
56
50
  return .init()
57
51
  }
58
- }(), { () -> bridge.std__optional_double_ in
59
- if let __unwrappedValue = uiUpdateIntervalMs {
60
- return bridge.create_std__optional_double_(__unwrappedValue)
61
- } else {
62
- return .init()
63
- }
64
52
  }(), { () -> bridge.Func_void_AntiSpoofingResult in
65
53
  let __closureWrapper = Func_void_AntiSpoofingResult(onResult)
66
54
  return bridge.create_Func_void_AntiSpoofingResult(__closureWrapper.toUnsafe())
@@ -95,10 +83,6 @@ public extension SpoofDetectorOutputOptions {
95
83
  }
96
84
 
97
85
  @inline(__always)
98
- var targetResolution: Size? {
99
- return self.__targetResolution.value
100
- }
101
-
102
86
  @inline(__always)
103
87
  var antispoofLevel: Double? {
104
88
  return { () -> Double? in
@@ -159,18 +143,6 @@ public extension SpoofDetectorOutputOptions {
159
143
  }()
160
144
  }
161
145
 
162
- @inline(__always)
163
- var uiUpdateIntervalMs: Double? {
164
- return { () -> Double? in
165
- if bridge.has_value_std__optional_double_(self.__uiUpdateIntervalMs) {
166
- let __unwrapped = bridge.get_std__optional_double_(self.__uiUpdateIntervalMs)
167
- return __unwrapped
168
- } else {
169
- return nil
170
- }
171
- }()
172
- }
173
-
174
146
  @inline(__always)
175
147
  var onResult: (_ result: AntiSpoofingResult) -> Void {
176
148
  return { () -> (AntiSpoofingResult) -> Void in
@@ -28,8 +28,6 @@
28
28
  #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
29
29
  #endif
30
30
 
31
- // Forward declaration of `Size` to properly resolve imports.
32
- namespace margelo::nitro::camera::spoofdetector { struct Size; }
33
31
  // Forward declaration of `AntiSpoofingResult` to properly resolve imports.
34
32
  namespace margelo::nitro::camera::spoofdetector { struct AntiSpoofingResult; }
35
33
  // Forward declaration of `SpoofDetectedFace` to properly resolve imports.
@@ -37,7 +35,6 @@ namespace margelo::nitro::camera::spoofdetector { struct SpoofDetectedFace; }
37
35
  // Forward declaration of `SpoofDetectedFaceBounds` to properly resolve imports.
38
36
  namespace margelo::nitro::camera::spoofdetector { struct SpoofDetectedFaceBounds; }
39
37
 
40
- #include "Size.hpp"
41
38
  #include <optional>
42
39
  #include "AntiSpoofingResult.hpp"
43
40
  #include <functional>
@@ -53,13 +50,11 @@ namespace margelo::nitro::camera::spoofdetector {
53
50
  */
54
51
  struct SpoofDetectorOutputOptions final {
55
52
  public:
56
- std::optional<Size> targetResolution SWIFT_PRIVATE;
57
53
  std::optional<double> antispoofLevel SWIFT_PRIVATE;
58
54
  std::optional<double> stableFrames SWIFT_PRIVATE;
59
55
  std::optional<double> requiredLiveFrames SWIFT_PRIVATE;
60
56
  std::optional<double> laplacianThreshold SWIFT_PRIVATE;
61
57
  std::optional<double> maxNeuralSpoofScore SWIFT_PRIVATE;
62
- std::optional<double> uiUpdateIntervalMs SWIFT_PRIVATE;
63
58
  std::function<void(const AntiSpoofingResult& /* result */)> onResult SWIFT_PRIVATE;
64
59
  std::optional<std::function<void(const std::vector<SpoofDetectedFace>& /* faces */)>> onFacesDetected SWIFT_PRIVATE;
65
60
  std::optional<std::function<void(const SpoofDetectedFaceBounds& /* face */, const AntiSpoofingResult& /* result */)>> onStableFaceDetected SWIFT_PRIVATE;
@@ -67,7 +62,7 @@ namespace margelo::nitro::camera::spoofdetector {
67
62
 
68
63
  public:
69
64
  SpoofDetectorOutputOptions() = default;
70
- explicit SpoofDetectorOutputOptions(std::optional<Size> targetResolution, std::optional<double> antispoofLevel, std::optional<double> stableFrames, std::optional<double> requiredLiveFrames, std::optional<double> laplacianThreshold, std::optional<double> maxNeuralSpoofScore, std::optional<double> uiUpdateIntervalMs, std::function<void(const AntiSpoofingResult& /* result */)> onResult, std::optional<std::function<void(const std::vector<SpoofDetectedFace>& /* faces */)>> onFacesDetected, std::optional<std::function<void(const SpoofDetectedFaceBounds& /* face */, const AntiSpoofingResult& /* result */)>> onStableFaceDetected, std::optional<std::function<void(const std::exception_ptr& /* error */)>> onError): targetResolution(targetResolution), antispoofLevel(antispoofLevel), stableFrames(stableFrames), requiredLiveFrames(requiredLiveFrames), laplacianThreshold(laplacianThreshold), maxNeuralSpoofScore(maxNeuralSpoofScore), uiUpdateIntervalMs(uiUpdateIntervalMs), onResult(onResult), onFacesDetected(onFacesDetected), onStableFaceDetected(onStableFaceDetected), onError(onError) {}
65
+ explicit SpoofDetectorOutputOptions(std::optional<double> antispoofLevel, std::optional<double> stableFrames, std::optional<double> requiredLiveFrames, std::optional<double> laplacianThreshold, std::optional<double> maxNeuralSpoofScore, std::function<void(const AntiSpoofingResult& /* result */)> onResult, std::optional<std::function<void(const std::vector<SpoofDetectedFace>& /* faces */)>> onFacesDetected, std::optional<std::function<void(const SpoofDetectedFaceBounds& /* face */, const AntiSpoofingResult& /* result */)>> onStableFaceDetected, std::optional<std::function<void(const std::exception_ptr& /* error */)>> onError): antispoofLevel(antispoofLevel), stableFrames(stableFrames), requiredLiveFrames(requiredLiveFrames), laplacianThreshold(laplacianThreshold), maxNeuralSpoofScore(maxNeuralSpoofScore), onResult(onResult), onFacesDetected(onFacesDetected), onStableFaceDetected(onStableFaceDetected), onError(onError) {}
71
66
 
72
67
  public:
73
68
  // SpoofDetectorOutputOptions is not equatable because these properties are not equatable: onResult, onFacesDetected, onStableFaceDetected, onError
@@ -83,13 +78,11 @@ namespace margelo::nitro {
83
78
  static inline margelo::nitro::camera::spoofdetector::SpoofDetectorOutputOptions fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
84
79
  jsi::Object obj = arg.asObject(runtime);
85
80
  return margelo::nitro::camera::spoofdetector::SpoofDetectorOutputOptions(
86
- JSIConverter<std::optional<margelo::nitro::camera::spoofdetector::Size>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "targetResolution"))),
87
81
  JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "antispoofLevel"))),
88
82
  JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "stableFrames"))),
89
83
  JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "requiredLiveFrames"))),
90
84
  JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "laplacianThreshold"))),
91
85
  JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "maxNeuralSpoofScore"))),
92
- JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "uiUpdateIntervalMs"))),
93
86
  JSIConverter<std::function<void(const margelo::nitro::camera::spoofdetector::AntiSpoofingResult&)>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "onResult"))),
94
87
  JSIConverter<std::optional<std::function<void(const std::vector<margelo::nitro::camera::spoofdetector::SpoofDetectedFace>&)>>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "onFacesDetected"))),
95
88
  JSIConverter<std::optional<std::function<void(const margelo::nitro::camera::spoofdetector::SpoofDetectedFaceBounds&, const margelo::nitro::camera::spoofdetector::AntiSpoofingResult&)>>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "onStableFaceDetected"))),
@@ -98,13 +91,11 @@ namespace margelo::nitro {
98
91
  }
99
92
  static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::camera::spoofdetector::SpoofDetectorOutputOptions& arg) {
100
93
  jsi::Object obj(runtime);
101
- obj.setProperty(runtime, PropNameIDCache::get(runtime, "targetResolution"), JSIConverter<std::optional<margelo::nitro::camera::spoofdetector::Size>>::toJSI(runtime, arg.targetResolution));
102
94
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "antispoofLevel"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.antispoofLevel));
103
95
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "stableFrames"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.stableFrames));
104
96
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "requiredLiveFrames"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.requiredLiveFrames));
105
97
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "laplacianThreshold"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.laplacianThreshold));
106
98
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "maxNeuralSpoofScore"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.maxNeuralSpoofScore));
107
- obj.setProperty(runtime, PropNameIDCache::get(runtime, "uiUpdateIntervalMs"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.uiUpdateIntervalMs));
108
99
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "onResult"), JSIConverter<std::function<void(const margelo::nitro::camera::spoofdetector::AntiSpoofingResult&)>>::toJSI(runtime, arg.onResult));
109
100
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "onFacesDetected"), JSIConverter<std::optional<std::function<void(const std::vector<margelo::nitro::camera::spoofdetector::SpoofDetectedFace>&)>>>::toJSI(runtime, arg.onFacesDetected));
110
101
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "onStableFaceDetected"), JSIConverter<std::optional<std::function<void(const margelo::nitro::camera::spoofdetector::SpoofDetectedFaceBounds&, const margelo::nitro::camera::spoofdetector::AntiSpoofingResult&)>>>::toJSI(runtime, arg.onStableFaceDetected));
@@ -119,13 +110,11 @@ namespace margelo::nitro {
119
110
  if (!nitro::isPlainObject(runtime, obj)) {
120
111
  return false;
121
112
  }
122
- if (!JSIConverter<std::optional<margelo::nitro::camera::spoofdetector::Size>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "targetResolution")))) return false;
123
113
  if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "antispoofLevel")))) return false;
124
114
  if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "stableFrames")))) return false;
125
115
  if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "requiredLiveFrames")))) return false;
126
116
  if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "laplacianThreshold")))) return false;
127
117
  if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "maxNeuralSpoofScore")))) return false;
128
- if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "uiUpdateIntervalMs")))) return false;
129
118
  if (!JSIConverter<std::function<void(const margelo::nitro::camera::spoofdetector::AntiSpoofingResult&)>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "onResult")))) return false;
130
119
  if (!JSIConverter<std::optional<std::function<void(const std::vector<margelo::nitro::camera::spoofdetector::SpoofDetectedFace>&)>>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "onFacesDetected")))) return false;
131
120
  if (!JSIConverter<std::optional<std::function<void(const margelo::nitro::camera::spoofdetector::SpoofDetectedFaceBounds&, const margelo::nitro::camera::spoofdetector::AntiSpoofingResult&)>>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "onStableFaceDetected")))) return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-vision-camera-spoof-detector",
3
- "version": "1.3.4",
3
+ "version": "1.3.6",
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": {
@@ -1,4 +1,4 @@
1
- import type { CameraOutput, Size } from 'react-native-vision-camera'
1
+ import type { CameraOutput } from 'react-native-vision-camera'
2
2
  import type { HybridObject } from 'react-native-nitro-modules'
3
3
 
4
4
  export interface AntiSpoofingResult {
@@ -20,13 +20,11 @@ export interface SpoofDetectedFace {
20
20
  }
21
21
 
22
22
  export interface SpoofDetectorOutputOptions {
23
- targetResolution?: Size
24
23
  antispoofLevel?: number
25
24
  stableFrames?: number
26
25
  requiredLiveFrames?: number
27
26
  laplacianThreshold?: number
28
27
  maxNeuralSpoofScore?: number
29
- uiUpdateIntervalMs?: number
30
28
  onResult: (result: AntiSpoofingResult) => void
31
29
  onFacesDetected?: (faces: SpoofDetectedFace[]) => void
32
30
  onStableFaceDetected?: (