react-native-vision-camera-spoof-detector 1.2.10 → 1.3.0
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 -48
- package/index.d.ts +19 -36
- package/ios/FaceAntiSpoofManager.swift +0 -4
- package/ios/HybridSpoofDetectorOutput.swift +0 -12
- 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.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,43 +236,29 @@ 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
|
-
```
|
|
236
|
-
|
|
239
|
+
The score object delivered to `onResult` and `onStableFaceDetected` has the four numeric fields shown under [`useFaceAntiSpoofFrameOutput`](#usefaceantispoofframeoutputoptions).
|
|
237
240
|
Result fields:
|
|
238
241
|
|
|
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
242
|
- `neuralNetworkScore`: raw model score from the TFLite classifier
|
|
242
243
|
- `laplacianScore`: image variance / quality score used to detect blur or non-real textures
|
|
243
244
|
- `combinedScore`: combined weighted score constructed by the native implementation
|
|
244
|
-
- `confidence`:
|
|
245
|
+
- `confidence`: score used with the configured thresholds; not a calibrated probability
|
|
245
246
|
|
|
246
247
|
## Android and iOS implementation notes
|
|
247
248
|
|
|
248
249
|
### Android
|
|
249
250
|
|
|
250
|
-
- Uses
|
|
251
|
-
-
|
|
252
|
-
- Uses
|
|
253
|
-
-
|
|
251
|
+
- Uses CameraX `ImageAnalysis`, ML Kit face detection, and the bundled TensorFlow Lite model
|
|
252
|
+
- Prefers GPU inference, falls back to NNAPI, then CPU
|
|
253
|
+
- 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
|
|
254
255
|
|
|
255
256
|
### iOS
|
|
256
257
|
|
|
257
|
-
- Uses
|
|
258
|
-
-
|
|
259
|
-
-
|
|
260
|
-
-
|
|
261
|
-
- Returns the evaluation result through the same `onResult` callback contract
|
|
258
|
+
- Uses `AVCaptureVideoDataOutput`, Apple Vision face/landmark detection, and the bundled TensorFlow Lite model
|
|
259
|
+
- Uses Metal when available, with CPU fallback
|
|
260
|
+
- 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
|
|
262
262
|
|
|
263
263
|
## Troubleshooting
|
|
264
264
|
|
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
|
// ============================================================================
|
|
@@ -84,8 +70,6 @@ export interface SpoofDetectedFace {
|
|
|
84
70
|
* Anti-spoofing detection state
|
|
85
71
|
*/
|
|
86
72
|
export interface AntiSpoofState {
|
|
87
|
-
/** Whether face is detected as live */
|
|
88
|
-
isLive: boolean;
|
|
89
73
|
/** Confidence score (0.0-1.0) */
|
|
90
74
|
confidence: number;
|
|
91
75
|
/** Consecutive frames detected as live */
|
|
@@ -160,7 +144,6 @@ export interface FacesUpdateData {
|
|
|
160
144
|
* Anti-spoof update callback data
|
|
161
145
|
*/
|
|
162
146
|
export interface OnAntiSpoofUpdateData {
|
|
163
|
-
isLive: boolean;
|
|
164
147
|
confidence: number;
|
|
165
148
|
rawResult?: FaceAntiSpoofingResult;
|
|
166
149
|
consecutiveLiveFrames: number;
|
|
@@ -290,15 +273,16 @@ export interface UseFaceDetectionFrameProcessorReturn {
|
|
|
290
273
|
* The callback runs on the React Native runtime after native inference.
|
|
291
274
|
*/
|
|
292
275
|
export interface UseFaceAntiSpoofFrameOutputOptions extends Partial<FrameOutputOptions> {
|
|
293
|
-
antispoofLevel?: number;
|
|
294
|
-
stableFrames?: number;
|
|
295
|
-
requiredLiveFrames?: number;
|
|
296
|
-
laplacianThreshold?: number;
|
|
297
|
-
maxNeuralSpoofScore?: number;
|
|
298
|
-
uiUpdateIntervalMs?: number;
|
|
276
|
+
antispoofLevel?: number;
|
|
277
|
+
stableFrames?: number;
|
|
278
|
+
requiredLiveFrames?: number;
|
|
279
|
+
laplacianThreshold?: number;
|
|
280
|
+
maxNeuralSpoofScore?: number;
|
|
281
|
+
uiUpdateIntervalMs?: number;
|
|
299
282
|
onResult?: (result: FaceAntiSpoofingResult) => void;
|
|
300
|
-
onFacesDetected?: (faces: SpoofDetectedFace[]) => void;
|
|
301
|
-
onStableFaceDetected?: (face: FaceRect, result: FaceAntiSpoofingResult) => void;
|
|
283
|
+
onFacesDetected?: (faces: SpoofDetectedFace[]) => void;
|
|
284
|
+
onStableFaceDetected?: (face: FaceRect, result: FaceAntiSpoofingResult) => void;
|
|
285
|
+
onError?: (error: Error) => void;
|
|
302
286
|
}
|
|
303
287
|
|
|
304
288
|
/** Create a VisionCamera 5 frame output backed by the native detector. */
|
|
@@ -306,8 +290,8 @@ export function useFaceAntiSpoofFrameOutput(
|
|
|
306
290
|
options?: UseFaceAntiSpoofFrameOutputOptions,
|
|
307
291
|
): CameraFrameOutput;
|
|
308
292
|
|
|
309
|
-
export function resetFaceAntiSpoofFrameOutput(output: CameraFrameOutput): void;
|
|
310
|
-
|
|
293
|
+
export function resetFaceAntiSpoofFrameOutput(output: CameraFrameOutput): void;
|
|
294
|
+
|
|
311
295
|
// ============================================================================
|
|
312
296
|
// Module Functions
|
|
313
297
|
// ============================================================================
|
|
@@ -321,8 +305,8 @@ export function resetFaceAntiSpoofFrameOutput(output: CameraFrameOutput): void;
|
|
|
321
305
|
* const frameProcessor = useFrameProcessor((frame) => {
|
|
322
306
|
* 'worklet';
|
|
323
307
|
* const result = faceAntiSpoofFrameProcessor(frame);
|
|
324
|
-
* if (result
|
|
325
|
-
* //
|
|
308
|
+
* if (result && result.confidence > 0.5) {
|
|
309
|
+
* // Evaluate confidence together with neuralNetworkScore and laplacianScore.
|
|
326
310
|
* }
|
|
327
311
|
* }, []);
|
|
328
312
|
* ```
|
|
@@ -496,4 +480,3 @@ export const DEFAULT_REQUIRED_BLINKS = 3;
|
|
|
496
480
|
* Blink detection threshold (eye closure probability)
|
|
497
481
|
*/
|
|
498
482
|
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
|
|
@@ -109,7 +108,6 @@ final class HybridSpoofDetectorOutput: HybridCameraOutputSpec, NativeCameraOutpu
|
|
|
109
108
|
self.stableCount = 0
|
|
110
109
|
self.lastFaceBounds = nil
|
|
111
110
|
self.consecutiveLiveFrames = 0
|
|
112
|
-
self.isLive = false
|
|
113
111
|
self.lastSpoofResult = nil
|
|
114
112
|
self.lastFaceCount = -1
|
|
115
113
|
self.lastFacesUpdateAt = 0
|
|
@@ -160,13 +158,8 @@ final class HybridSpoofDetectorOutput: HybridCameraOutputSpec, NativeCameraOutpu
|
|
|
160
158
|
|
|
161
159
|
do {
|
|
162
160
|
let result = try FaceAntiSpoofManager.process(input: input)
|
|
163
|
-
let isLive = result.neuralNetworkScore < maxNeuralSpoofScore
|
|
164
|
-
&& result.confidence >= antispoofLevel
|
|
165
|
-
&& result.laplacianScore >= laplacianThreshold
|
|
166
161
|
processAntiSpoofResult(
|
|
167
162
|
AntiSpoofingResult(
|
|
168
|
-
isLive: isLive,
|
|
169
|
-
label: isLive ? "Live Face" : "Spoof Face",
|
|
170
163
|
neuralNetworkScore: result.neuralNetworkScore,
|
|
171
164
|
laplacianScore: result.laplacianScore,
|
|
172
165
|
combinedScore: result.combinedScore,
|
|
@@ -243,7 +236,6 @@ final class HybridSpoofDetectorOutput: HybridCameraOutputSpec, NativeCameraOutpu
|
|
|
243
236
|
stableCount = 0
|
|
244
237
|
lastFaceBounds = nil
|
|
245
238
|
consecutiveLiveFrames = 0
|
|
246
|
-
isLive = false
|
|
247
239
|
lastSpoofResult = nil
|
|
248
240
|
}
|
|
249
241
|
|
|
@@ -259,7 +251,6 @@ final class HybridSpoofDetectorOutput: HybridCameraOutputSpec, NativeCameraOutpu
|
|
|
259
251
|
lastSpoofResult = result
|
|
260
252
|
if result.neuralNetworkScore >= maxNeuralSpoofScore {
|
|
261
253
|
consecutiveLiveFrames = 0
|
|
262
|
-
isLive = false
|
|
263
254
|
} else {
|
|
264
255
|
let meetsConfidence = result.confidence >= antispoofLevel
|
|
265
256
|
let meetsLaplacian = result.laplacianScore >= laplacianThreshold
|
|
@@ -268,7 +259,6 @@ final class HybridSpoofDetectorOutput: HybridCameraOutputSpec, NativeCameraOutpu
|
|
|
268
259
|
} else {
|
|
269
260
|
consecutiveLiveFrames = 0
|
|
270
261
|
}
|
|
271
|
-
isLive = consecutiveLiveFrames >= requiredLiveFrames
|
|
272
262
|
}
|
|
273
263
|
|
|
274
264
|
let now = ProcessInfo.processInfo.systemUptime
|
|
@@ -282,7 +272,6 @@ final class HybridSpoofDetectorOutput: HybridCameraOutputSpec, NativeCameraOutpu
|
|
|
282
272
|
private func notifyStableFaceIfReady() {
|
|
283
273
|
guard !captured,
|
|
284
274
|
stableCount >= stableFrames,
|
|
285
|
-
isLive,
|
|
286
275
|
consecutiveLiveFrames >= requiredLiveFrames,
|
|
287
276
|
let bounds = lastFaceBounds,
|
|
288
277
|
let result = lastSpoofResult,
|
|
@@ -429,7 +418,6 @@ final class HybridSpoofDetectorOutput: HybridCameraOutputSpec, NativeCameraOutpu
|
|
|
429
418
|
|
|
430
419
|
private func invalidateLiveEvidence() {
|
|
431
420
|
consecutiveLiveFrames = 0
|
|
432
|
-
isLive = false
|
|
433
421
|
lastSpoofResult = nil
|
|
434
422
|
}
|
|
435
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.
|
|
3
|
+
"version": "1.3.0",
|
|
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
|