react-native-vision-camera-spoof-detector 1.2.9 → 1.2.11
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 +48 -47
- package/index.d.ts +19 -33
- package/ios/FaceAntiSpoofManager.swift +0 -4
- package/ios/HybridSpoofDetectorOutput.swift +9 -13
- package/nitrogen/generated/ios/swift/AntiSpoofingResult.swift +2 -12
- package/nitrogen/generated/shared/c++/AntiSpoofingResult.hpp +1 -13
- package/package.json +1 -1
- package/src/specs/SpoofDetectorFactory.nitro.ts +0 -2
package/README.md
CHANGED
|
@@ -3,17 +3,18 @@
|
|
|
3
3
|
[](https://badge.fury.io/js/react-native-vision-camera-spoof-detector)
|
|
4
4
|
[](https://github.com/dpraful/react-native-vision-camera-spoof-detector)
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
Face anti-spoofing and liveness scoring for React Native Vision Camera 5. A Nitro-backed native camera output detects eligible faces, scores a face-aligned image with the bundled TensorFlow Lite model, and reports the numeric scores to JavaScript on Android and iOS.
|
|
7
7
|
|
|
8
8
|
## Features
|
|
9
9
|
|
|
10
10
|
- Native Android and iOS detection pipeline
|
|
11
11
|
- Vision Camera 5 `CameraOutput` integration via Nitro hybrid objects
|
|
12
|
-
- TensorFlow Lite inference with GPU or
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
- Optional
|
|
16
|
-
-
|
|
12
|
+
- TensorFlow Lite inference with GPU, NNAPI, or CPU fallback on Android and Metal/CPU on iOS
|
|
13
|
+
- Native face detection (ML Kit on Android, Vision on iOS); no separate face-detector output is needed
|
|
14
|
+
- Face size, frame-edge, pose, landmark, brightness, and liveness-quality gates
|
|
15
|
+
- Optional callbacks for scores, detected faces, stable-face capture, and errors
|
|
16
|
+
- Output reset without recreating the camera output
|
|
17
|
+
- Optional target-resolution and liveness threshold configuration
|
|
17
18
|
|
|
18
19
|
## Requirements
|
|
19
20
|
|
|
@@ -22,7 +23,7 @@ High-performance face anti-spoofing and liveness detection for React Native Visi
|
|
|
22
23
|
- `react-native-nitro-modules` `^0.37.1`
|
|
23
24
|
- `react-native-worklets` `^0.12.0`
|
|
24
25
|
- `react-native-vision-camera-worklets` `^5.0.0`
|
|
25
|
-
- iOS
|
|
26
|
+
- iOS 15.5 or later
|
|
26
27
|
- Android support through the package's native modules and bundled TensorFlow Lite model
|
|
27
28
|
|
|
28
29
|
## Installation
|
|
@@ -135,7 +136,7 @@ const styles = StyleSheet.create({
|
|
|
135
136
|
});
|
|
136
137
|
```
|
|
137
138
|
|
|
138
|
-
The
|
|
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
140
|
|
|
140
141
|
## API reference
|
|
141
142
|
|
|
@@ -160,6 +161,7 @@ Options:
|
|
|
160
161
|
|
|
161
162
|
```ts
|
|
162
163
|
interface UseFaceAntiSpoofFrameOutputOptions {
|
|
164
|
+
targetResolution?: { width: number; height: number };
|
|
163
165
|
antispoofLevel?: number;
|
|
164
166
|
stableFrames?: number;
|
|
165
167
|
requiredLiveFrames?: number;
|
|
@@ -168,37 +170,49 @@ interface UseFaceAntiSpoofFrameOutputOptions {
|
|
|
168
170
|
uiUpdateIntervalMs?: number;
|
|
169
171
|
onFacesDetected?: (faces: SpoofDetectedFace[]) => void;
|
|
170
172
|
onResult?: (result: FaceAntiSpoofingResult) => void;
|
|
171
|
-
onStableFaceDetected?: (face:
|
|
173
|
+
onStableFaceDetected?: (face: SpoofDetectedFace['bounds'], result: FaceAntiSpoofingResult) => void;
|
|
172
174
|
onError?: (error: Error) => void;
|
|
173
175
|
}
|
|
176
|
+
|
|
177
|
+
interface FaceAntiSpoofingResult {
|
|
178
|
+
neuralNetworkScore: number;
|
|
179
|
+
laplacianScore: number;
|
|
180
|
+
combinedScore: number;
|
|
181
|
+
confidence: number;
|
|
182
|
+
}
|
|
174
183
|
```
|
|
175
184
|
|
|
176
|
-
Android
|
|
185
|
+
The detector considers only one eligible face per frame. Android uses ML Kit; iOS uses Apple Vision. Both require a sufficiently large face, face landmarks, a near-frontal pose, and a face inside the frame margin. The model input is a square face crop aligned to the eyes. Frames rejected for brightness, face count, or score thresholds clear the consecutive-live-frame evidence.
|
|
177
186
|
|
|
178
|
-
|
|
187
|
+
`onFacesDetected` is optional and receives eligible faces as `{ bounds: { x, y, width, height } }`. `onResult` receives numeric scores only. It does **not** return `isLive` or `label`; use the scores and your own calibrated policy. `onStableFaceDetected` is the positive event that the configured face-stability and consecutive-live-frame gates passed, and receives the face bounds and latest scores. This event is not a guarantee against presentation attacks.
|
|
179
188
|
|
|
180
|
-
|
|
189
|
+
Default output options on both platforms:
|
|
181
190
|
|
|
182
|
-
|
|
191
|
+
| Option | Default | Meaning |
|
|
192
|
+
|---|---:|---|
|
|
193
|
+
| `antispoofLevel` | `0.4` | Minimum confidence for a frame to count toward the live-frame streak |
|
|
194
|
+
| `stableFrames` | `3` | Eligible face frames required before stable-face notification |
|
|
195
|
+
| `requiredLiveFrames` | `3` | Consecutive score-passing frames required before notification |
|
|
196
|
+
| `laplacianThreshold` | `2000` | Minimum Laplacian score for a frame to pass |
|
|
197
|
+
| `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 |
|
|
183
200
|
|
|
184
|
-
|
|
185
|
-
node --test scripts/evaluate-antispoof.test.mjs
|
|
186
|
-
node scripts/evaluate-antispoof.mjs --input path/to/holdout.jsonl --required-frames 3
|
|
187
|
-
```
|
|
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.
|
|
188
202
|
|
|
189
|
-
|
|
203
|
+
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.
|
|
190
204
|
|
|
191
|
-
|
|
192
|
-
{"presentationId":"person01-print-office-40cm-deviceA","groundTruth":"attack","attackType":"print","lighting":"office","distance":"40cm","device":"deviceA","neuralNetworkScore":0.14,"laplacianScore":2100,"confidence":0.55,"qualityPass":true,"faceCount":1}
|
|
193
|
-
```
|
|
205
|
+
To clear the stable-face state and allow another `onStableFaceDetected` callback:
|
|
194
206
|
|
|
195
|
-
|
|
207
|
+
```ts
|
|
208
|
+
resetFaceAntiSpoofFrameOutput(antiSpoofOutput);
|
|
209
|
+
```
|
|
196
210
|
|
|
197
211
|
---
|
|
198
212
|
|
|
199
213
|
### `initializeFaceAntiSpoof()`
|
|
200
214
|
|
|
201
|
-
|
|
215
|
+
Optional check for the legacy `FaceAntiSpoof` native module. The camera output uses the Nitro native output; it initializes or accesses the model as needed when frames are processed, so this function is not required before creating the output.
|
|
202
216
|
|
|
203
217
|
```ts
|
|
204
218
|
const initialized = await initializeFaceAntiSpoof();
|
|
@@ -210,7 +224,7 @@ Returns `Promise<boolean>`.
|
|
|
210
224
|
|
|
211
225
|
### `isFaceAntiSpoofAvailable()`
|
|
212
226
|
|
|
213
|
-
Checks whether the
|
|
227
|
+
Checks whether the legacy `FaceAntiSpoof` React Native module is registered. It does not check camera permission, whether a camera is available, or whether the Nitro camera output can process a frame.
|
|
214
228
|
|
|
215
229
|
```ts
|
|
216
230
|
const available = isFaceAntiSpoofAvailable();
|
|
@@ -222,42 +236,30 @@ Returns `boolean`.
|
|
|
222
236
|
|
|
223
237
|
### `FaceAntiSpoofingResult`
|
|
224
238
|
|
|
225
|
-
|
|
226
|
-
interface FaceAntiSpoofingResult {
|
|
227
|
-
isLive: boolean;
|
|
228
|
-
label: string;
|
|
229
|
-
neuralNetworkScore: number;
|
|
230
|
-
laplacianScore: number;
|
|
231
|
-
combinedScore: number;
|
|
232
|
-
confidence: number;
|
|
233
|
-
error?: string;
|
|
234
|
-
}
|
|
235
|
-
```
|
|
239
|
+
The score object delivered to `onResult` and `onStableFaceDetected` has the four numeric fields shown under [`useFaceAntiSpoofFrameOutput`](#usefaceantispoofframeoutputoptions). It does not include a boolean live decision or a text label.
|
|
236
240
|
|
|
237
241
|
Result fields:
|
|
238
242
|
|
|
239
|
-
- `isLive`: true for a likely real face, false for a spoof attempt
|
|
240
|
-
- `label`: human-readable label such as `Live Face` or `Spoof Face`
|
|
241
243
|
- `neuralNetworkScore`: raw model score from the TFLite classifier
|
|
242
244
|
- `laplacianScore`: image variance / quality score used to detect blur or non-real textures
|
|
243
245
|
- `combinedScore`: combined weighted score constructed by the native implementation
|
|
244
|
-
- `confidence`:
|
|
246
|
+
- `confidence`: score used with the configured thresholds; not a calibrated probability
|
|
245
247
|
|
|
246
248
|
## Android and iOS implementation notes
|
|
247
249
|
|
|
248
250
|
### Android
|
|
249
251
|
|
|
250
|
-
- Uses
|
|
251
|
-
-
|
|
252
|
-
- Uses
|
|
253
|
-
-
|
|
252
|
+
- Uses CameraX `ImageAnalysis`, ML Kit face detection, and the bundled TensorFlow Lite model
|
|
253
|
+
- Prefers GPU inference, falls back to NNAPI, then CPU
|
|
254
|
+
- Uses YUV input, a brightness gate, face-size/frame-margin/pose/landmark checks, and a padded, eye-aligned face crop
|
|
255
|
+
- Uses `MirrorMode.AUTO` and applies a requested analysis resolution when provided
|
|
254
256
|
|
|
255
257
|
### iOS
|
|
256
258
|
|
|
257
|
-
- Uses
|
|
258
|
-
-
|
|
259
|
-
-
|
|
260
|
-
-
|
|
259
|
+
- Uses `AVCaptureVideoDataOutput`, Apple Vision face/landmark detection, and the bundled TensorFlow Lite model
|
|
260
|
+
- Uses Metal when available, with CPU fallback
|
|
261
|
+
- Uses BGRA input, a brightness gate, face-size/frame-margin/pose/landmark checks, and a padded, eye-aligned face crop
|
|
262
|
+
- Automatically adjusts video mirroring and only constrains resolution when `targetResolution` is provided
|
|
261
263
|
|
|
262
264
|
## Troubleshooting
|
|
263
265
|
|
|
@@ -301,4 +303,3 @@ MIT. See [LICENSE](./LICENSE).
|
|
|
301
303
|
## Author
|
|
302
304
|
|
|
303
305
|
JESCON TECHNOLOGIES PVT LTD
|
|
304
|
-
|
package/index.d.ts
CHANGED
|
@@ -16,19 +16,6 @@ import type { SharedValue } from 'react-native-reanimated';
|
|
|
16
16
|
* Contains comprehensive information about face liveness detection
|
|
17
17
|
*/
|
|
18
18
|
export interface FaceAntiSpoofingResult {
|
|
19
|
-
/**
|
|
20
|
-
* Whether the face is live (real) or a spoof attempt
|
|
21
|
-
* @true - Face is real/live
|
|
22
|
-
* @false - Face is likely a spoof/fake
|
|
23
|
-
*/
|
|
24
|
-
isLive: boolean;
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Human-readable label
|
|
28
|
-
* @values "Live Face" | "Spoof Face"
|
|
29
|
-
*/
|
|
30
|
-
label: string;
|
|
31
|
-
|
|
32
19
|
/**
|
|
33
20
|
* Neural network confidence score
|
|
34
21
|
* Range: 0.0 to 1.0
|
|
@@ -52,10 +39,9 @@ export interface FaceAntiSpoofingResult {
|
|
|
52
39
|
combinedScore: number;
|
|
53
40
|
|
|
54
41
|
/**
|
|
55
|
-
*
|
|
56
|
-
* @optional Only present if an error occurred
|
|
42
|
+
* Derived score used with the configured liveness thresholds
|
|
57
43
|
*/
|
|
58
|
-
|
|
44
|
+
confidence: number;
|
|
59
45
|
}
|
|
60
46
|
|
|
61
47
|
/**
|
|
@@ -72,10 +58,10 @@ export interface FaceRect {
|
|
|
72
58
|
height: number;
|
|
73
59
|
}
|
|
74
60
|
|
|
75
|
-
export interface SpoofDetectedFace {
|
|
76
|
-
bounds: FaceRect;
|
|
77
|
-
}
|
|
78
|
-
|
|
61
|
+
export interface SpoofDetectedFace {
|
|
62
|
+
bounds: FaceRect;
|
|
63
|
+
}
|
|
64
|
+
|
|
79
65
|
// ============================================================================
|
|
80
66
|
// Anti-spoofing State & Configuration
|
|
81
67
|
// ============================================================================
|
|
@@ -290,15 +276,16 @@ export interface UseFaceDetectionFrameProcessorReturn {
|
|
|
290
276
|
* The callback runs on the React Native runtime after native inference.
|
|
291
277
|
*/
|
|
292
278
|
export interface UseFaceAntiSpoofFrameOutputOptions extends Partial<FrameOutputOptions> {
|
|
293
|
-
antispoofLevel?: number;
|
|
294
|
-
stableFrames?: number;
|
|
295
|
-
requiredLiveFrames?: number;
|
|
296
|
-
laplacianThreshold?: number;
|
|
297
|
-
maxNeuralSpoofScore?: number;
|
|
298
|
-
uiUpdateIntervalMs?: number;
|
|
279
|
+
antispoofLevel?: number;
|
|
280
|
+
stableFrames?: number;
|
|
281
|
+
requiredLiveFrames?: number;
|
|
282
|
+
laplacianThreshold?: number;
|
|
283
|
+
maxNeuralSpoofScore?: number;
|
|
284
|
+
uiUpdateIntervalMs?: number;
|
|
299
285
|
onResult?: (result: FaceAntiSpoofingResult) => void;
|
|
300
|
-
onFacesDetected?: (faces: SpoofDetectedFace[]) => void;
|
|
301
|
-
onStableFaceDetected?: (face: FaceRect, result: FaceAntiSpoofingResult) => void;
|
|
286
|
+
onFacesDetected?: (faces: SpoofDetectedFace[]) => void;
|
|
287
|
+
onStableFaceDetected?: (face: FaceRect, result: FaceAntiSpoofingResult) => void;
|
|
288
|
+
onError?: (error: Error) => void;
|
|
302
289
|
}
|
|
303
290
|
|
|
304
291
|
/** Create a VisionCamera 5 frame output backed by the native detector. */
|
|
@@ -306,8 +293,8 @@ export function useFaceAntiSpoofFrameOutput(
|
|
|
306
293
|
options?: UseFaceAntiSpoofFrameOutputOptions,
|
|
307
294
|
): CameraFrameOutput;
|
|
308
295
|
|
|
309
|
-
export function resetFaceAntiSpoofFrameOutput(output: CameraFrameOutput): void;
|
|
310
|
-
|
|
296
|
+
export function resetFaceAntiSpoofFrameOutput(output: CameraFrameOutput): void;
|
|
297
|
+
|
|
311
298
|
// ============================================================================
|
|
312
299
|
// Module Functions
|
|
313
300
|
// ============================================================================
|
|
@@ -321,8 +308,8 @@ export function resetFaceAntiSpoofFrameOutput(output: CameraFrameOutput): void;
|
|
|
321
308
|
* const frameProcessor = useFrameProcessor((frame) => {
|
|
322
309
|
* 'worklet';
|
|
323
310
|
* const result = faceAntiSpoofFrameProcessor(frame);
|
|
324
|
-
* if (result
|
|
325
|
-
* //
|
|
311
|
+
* if (result && result.confidence > 0.5) {
|
|
312
|
+
* // Evaluate confidence together with neuralNetworkScore and laplacianScore.
|
|
326
313
|
* }
|
|
327
314
|
* }, []);
|
|
328
315
|
* ```
|
|
@@ -496,4 +483,3 @@ export const DEFAULT_REQUIRED_BLINKS = 3;
|
|
|
496
483
|
* Blink detection threshold (eye closure probability)
|
|
497
484
|
*/
|
|
498
485
|
export const DEFAULT_BLINK_THRESHOLD = 0.3;
|
|
499
|
-
|
|
@@ -28,7 +28,6 @@ private final class IOSMetalDelegate: Delegate {
|
|
|
28
28
|
@objcMembers
|
|
29
29
|
public class FaceAntiSpoofManager: NSObject {
|
|
30
30
|
public struct DetectionResult {
|
|
31
|
-
let isLive: Bool
|
|
32
31
|
let neuralNetworkScore: Double
|
|
33
32
|
let laplacianScore: Double
|
|
34
33
|
let combinedScore: Double
|
|
@@ -178,10 +177,7 @@ public class FaceAntiSpoofManager: NSObject {
|
|
|
178
177
|
let laplacianScore = calculateLaplacianScore(input)
|
|
179
178
|
let combinedScore = calculateCombinedScore(neuralScore, laplacianScore)
|
|
180
179
|
let confidence = combinedScore
|
|
181
|
-
let isLive = neuralScore < 0.2 && laplacianScore > 1000
|
|
182
|
-
|
|
183
180
|
return DetectionResult(
|
|
184
|
-
isLive: isLive,
|
|
185
181
|
neuralNetworkScore: Double(neuralScore),
|
|
186
182
|
laplacianScore: Double(laplacianScore),
|
|
187
183
|
combinedScore: Double(combinedScore),
|
|
@@ -24,7 +24,6 @@ final class HybridSpoofDetectorOutput: HybridCameraOutputSpec, NativeCameraOutpu
|
|
|
24
24
|
private var stableCount = 0
|
|
25
25
|
private var lastFaceBounds: SpoofDetectedFaceBounds?
|
|
26
26
|
private var consecutiveLiveFrames = 0
|
|
27
|
-
private var isLive = false
|
|
28
27
|
private var lastSpoofResult: AntiSpoofingResult?
|
|
29
28
|
private var lastFaceCount = -1
|
|
30
29
|
private var lastFacesUpdateAt = 0.0
|
|
@@ -53,9 +52,13 @@ final class HybridSpoofDetectorOutput: HybridCameraOutputSpec, NativeCameraOutpu
|
|
|
53
52
|
}
|
|
54
53
|
|
|
55
54
|
var targetResolution: ResolutionRule {
|
|
56
|
-
let
|
|
57
|
-
|
|
58
|
-
}
|
|
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
|
+
)
|
|
59
62
|
let resolution: margelo.nitro.camera.Size
|
|
60
63
|
if isLowMemoryDevice && requestedResolution.width > 640 {
|
|
61
64
|
let scale = 640 / requestedResolution.width
|
|
@@ -87,6 +90,7 @@ final class HybridSpoofDetectorOutput: HybridCameraOutputSpec, NativeCameraOutpu
|
|
|
87
90
|
func configure(config: OutputConfiguration) {
|
|
88
91
|
guard let connection = output.connection(with: .video) else { return }
|
|
89
92
|
connection.preferredVideoStabilizationMode = .off
|
|
93
|
+
connection.automaticallyAdjustsVideoMirroring = true
|
|
90
94
|
}
|
|
91
95
|
|
|
92
96
|
func dispose() {
|
|
@@ -104,7 +108,6 @@ final class HybridSpoofDetectorOutput: HybridCameraOutputSpec, NativeCameraOutpu
|
|
|
104
108
|
self.stableCount = 0
|
|
105
109
|
self.lastFaceBounds = nil
|
|
106
110
|
self.consecutiveLiveFrames = 0
|
|
107
|
-
self.isLive = false
|
|
108
111
|
self.lastSpoofResult = nil
|
|
109
112
|
self.lastFaceCount = -1
|
|
110
113
|
self.lastFacesUpdateAt = 0
|
|
@@ -157,8 +160,6 @@ final class HybridSpoofDetectorOutput: HybridCameraOutputSpec, NativeCameraOutpu
|
|
|
157
160
|
let result = try FaceAntiSpoofManager.process(input: input)
|
|
158
161
|
processAntiSpoofResult(
|
|
159
162
|
AntiSpoofingResult(
|
|
160
|
-
isLive: result.isLive,
|
|
161
|
-
label: result.isLive ? "Live Face" : "Spoof Face",
|
|
162
163
|
neuralNetworkScore: result.neuralNetworkScore,
|
|
163
164
|
laplacianScore: result.laplacianScore,
|
|
164
165
|
combinedScore: result.combinedScore,
|
|
@@ -235,7 +236,6 @@ final class HybridSpoofDetectorOutput: HybridCameraOutputSpec, NativeCameraOutpu
|
|
|
235
236
|
stableCount = 0
|
|
236
237
|
lastFaceBounds = nil
|
|
237
238
|
consecutiveLiveFrames = 0
|
|
238
|
-
isLive = false
|
|
239
239
|
lastSpoofResult = nil
|
|
240
240
|
}
|
|
241
241
|
|
|
@@ -251,7 +251,6 @@ final class HybridSpoofDetectorOutput: HybridCameraOutputSpec, NativeCameraOutpu
|
|
|
251
251
|
lastSpoofResult = result
|
|
252
252
|
if result.neuralNetworkScore >= maxNeuralSpoofScore {
|
|
253
253
|
consecutiveLiveFrames = 0
|
|
254
|
-
isLive = false
|
|
255
254
|
} else {
|
|
256
255
|
let meetsConfidence = result.confidence >= antispoofLevel
|
|
257
256
|
let meetsLaplacian = result.laplacianScore >= laplacianThreshold
|
|
@@ -260,7 +259,6 @@ final class HybridSpoofDetectorOutput: HybridCameraOutputSpec, NativeCameraOutpu
|
|
|
260
259
|
} else {
|
|
261
260
|
consecutiveLiveFrames = 0
|
|
262
261
|
}
|
|
263
|
-
isLive = consecutiveLiveFrames >= requiredLiveFrames
|
|
264
262
|
}
|
|
265
263
|
|
|
266
264
|
let now = ProcessInfo.processInfo.systemUptime
|
|
@@ -274,7 +272,6 @@ final class HybridSpoofDetectorOutput: HybridCameraOutputSpec, NativeCameraOutpu
|
|
|
274
272
|
private func notifyStableFaceIfReady() {
|
|
275
273
|
guard !captured,
|
|
276
274
|
stableCount >= stableFrames,
|
|
277
|
-
isLive,
|
|
278
275
|
consecutiveLiveFrames >= requiredLiveFrames,
|
|
279
276
|
let bounds = lastFaceBounds,
|
|
280
277
|
let result = lastSpoofResult,
|
|
@@ -400,7 +397,7 @@ final class HybridSpoofDetectorOutput: HybridCameraOutputSpec, NativeCameraOutpu
|
|
|
400
397
|
box.minY >= marginY, box.maxY <= 1 - marginY,
|
|
401
398
|
box.width >= 0.18, box.height >= 0.18,
|
|
402
399
|
abs(face.yaw?.doubleValue ?? 0) <= 25 * .pi / 180,
|
|
403
|
-
abs(face.
|
|
400
|
+
abs(face.pitch?.doubleValue ?? 0) <= 25 * .pi / 180,
|
|
404
401
|
let landmarks = face.landmarks,
|
|
405
402
|
landmarks.leftEye != nil, landmarks.rightEye != nil,
|
|
406
403
|
landmarks.nose != nil, landmarks.outerLips != nil else {
|
|
@@ -421,7 +418,6 @@ final class HybridSpoofDetectorOutput: HybridCameraOutputSpec, NativeCameraOutpu
|
|
|
421
418
|
|
|
422
419
|
private func invalidateLiveEvidence() {
|
|
423
420
|
consecutiveLiveFrames = 0
|
|
424
|
-
isLive = false
|
|
425
421
|
lastSpoofResult = nil
|
|
426
422
|
}
|
|
427
423
|
}
|
|
@@ -18,18 +18,8 @@ public extension AntiSpoofingResult {
|
|
|
18
18
|
/**
|
|
19
19
|
* Create a new instance of `AntiSpoofingResult`.
|
|
20
20
|
*/
|
|
21
|
-
init(
|
|
22
|
-
self.init(
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
@inline(__always)
|
|
26
|
-
var isLive: Bool {
|
|
27
|
-
return self.__isLive
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
@inline(__always)
|
|
31
|
-
var label: String {
|
|
32
|
-
return String(self.__label)
|
|
21
|
+
init(neuralNetworkScore: Double, laplacianScore: Double, combinedScore: Double, confidence: Double) {
|
|
22
|
+
self.init(neuralNetworkScore, laplacianScore, combinedScore, confidence)
|
|
33
23
|
}
|
|
34
24
|
|
|
35
25
|
@inline(__always)
|
|
@@ -30,8 +30,6 @@
|
|
|
30
30
|
|
|
31
31
|
|
|
32
32
|
|
|
33
|
-
#include <string>
|
|
34
|
-
|
|
35
33
|
namespace margelo::nitro::camera::spoofdetector {
|
|
36
34
|
|
|
37
35
|
/**
|
|
@@ -39,8 +37,6 @@ namespace margelo::nitro::camera::spoofdetector {
|
|
|
39
37
|
*/
|
|
40
38
|
struct AntiSpoofingResult final {
|
|
41
39
|
public:
|
|
42
|
-
bool isLive SWIFT_PRIVATE;
|
|
43
|
-
std::string label SWIFT_PRIVATE;
|
|
44
40
|
double neuralNetworkScore SWIFT_PRIVATE;
|
|
45
41
|
double laplacianScore SWIFT_PRIVATE;
|
|
46
42
|
double combinedScore SWIFT_PRIVATE;
|
|
@@ -48,7 +44,7 @@ namespace margelo::nitro::camera::spoofdetector {
|
|
|
48
44
|
|
|
49
45
|
public:
|
|
50
46
|
AntiSpoofingResult() = default;
|
|
51
|
-
explicit AntiSpoofingResult(
|
|
47
|
+
explicit AntiSpoofingResult(double neuralNetworkScore, double laplacianScore, double combinedScore, double confidence): neuralNetworkScore(neuralNetworkScore), laplacianScore(laplacianScore), combinedScore(combinedScore), confidence(confidence) {}
|
|
52
48
|
|
|
53
49
|
public:
|
|
54
50
|
friend bool operator==(const AntiSpoofingResult& lhs, const AntiSpoofingResult& rhs) = default;
|
|
@@ -64,8 +60,6 @@ namespace margelo::nitro {
|
|
|
64
60
|
static inline margelo::nitro::camera::spoofdetector::AntiSpoofingResult fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
65
61
|
jsi::Object obj = arg.asObject(runtime);
|
|
66
62
|
return margelo::nitro::camera::spoofdetector::AntiSpoofingResult(
|
|
67
|
-
JSIConverter<bool>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "isLive"))),
|
|
68
|
-
JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "label"))),
|
|
69
63
|
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "neuralNetworkScore"))),
|
|
70
64
|
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "laplacianScore"))),
|
|
71
65
|
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "combinedScore"))),
|
|
@@ -74,10 +68,6 @@ namespace margelo::nitro {
|
|
|
74
68
|
}
|
|
75
69
|
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::camera::spoofdetector::AntiSpoofingResult& arg) {
|
|
76
70
|
jsi::Object obj(runtime);
|
|
77
|
-
#if !defined(__ANDROID__)
|
|
78
|
-
obj.setProperty(runtime, PropNameIDCache::get(runtime, "isLive"), JSIConverter<bool>::toJSI(runtime, arg.isLive));
|
|
79
|
-
obj.setProperty(runtime, PropNameIDCache::get(runtime, "label"), JSIConverter<std::string>::toJSI(runtime, arg.label));
|
|
80
|
-
#endif
|
|
81
71
|
obj.setProperty(runtime, PropNameIDCache::get(runtime, "neuralNetworkScore"), JSIConverter<double>::toJSI(runtime, arg.neuralNetworkScore));
|
|
82
72
|
obj.setProperty(runtime, PropNameIDCache::get(runtime, "laplacianScore"), JSIConverter<double>::toJSI(runtime, arg.laplacianScore));
|
|
83
73
|
obj.setProperty(runtime, PropNameIDCache::get(runtime, "combinedScore"), JSIConverter<double>::toJSI(runtime, arg.combinedScore));
|
|
@@ -92,8 +82,6 @@ namespace margelo::nitro {
|
|
|
92
82
|
if (!nitro::isPlainObject(runtime, obj)) {
|
|
93
83
|
return false;
|
|
94
84
|
}
|
|
95
|
-
if (!JSIConverter<bool>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "isLive")))) return false;
|
|
96
|
-
if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "label")))) return false;
|
|
97
85
|
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "neuralNetworkScore")))) return false;
|
|
98
86
|
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "laplacianScore")))) return false;
|
|
99
87
|
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "combinedScore")))) return false;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-vision-camera-spoof-detector",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.11",
|
|
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": {
|
|
@@ -2,8 +2,6 @@ import type { CameraOutput, Size } from 'react-native-vision-camera'
|
|
|
2
2
|
import type { HybridObject } from 'react-native-nitro-modules'
|
|
3
3
|
|
|
4
4
|
export interface AntiSpoofingResult {
|
|
5
|
-
isLive: boolean
|
|
6
|
-
label: string
|
|
7
5
|
neuralNetworkScore: number
|
|
8
6
|
laplacianScore: number
|
|
9
7
|
combinedScore: number
|