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

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.
Files changed (3) hide show
  1. package/README.md +1 -1
  2. package/index.d.ts +35 -437
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -14,7 +14,7 @@ Face anti-spoofing and liveness scoring for React Native Vision Camera 5. A Nitr
14
14
  - Face size, frame-edge, pose, landmark, brightness, and liveness-quality gates
15
15
  - Optional callbacks for scores, detected faces, stable-face capture, and errors
16
16
  - Output reset without recreating the camera output
17
- - Optional target-resolution and liveness threshold configuration
17
+ - Configurable liveness thresholds; uses Vision Camera's selected analysis resolution
18
18
 
19
19
  ## Requirements
20
20
 
package/index.d.ts CHANGED
@@ -1,60 +1,16 @@
1
- /**
2
- * React Native Vision Camera Face Anti-Spoofing Detector
3
- * High-performance face anti-spoofing and liveness detection module
4
- * TypeScript type definitions
5
- */
1
+ import type { CameraOutput } from 'react-native-vision-camera';
6
2
 
7
- import type { CameraFrameOutput, Frame, FrameOutputOptions, FrameProcessor } from 'react-native-vision-camera';
8
- import type { SharedValue } from 'react-native-reanimated';
9
-
10
- // ============================================================================
11
- // Core Detection Results
12
- // ============================================================================
13
-
14
- /**
15
- * Face anti-spoofing detection result
16
- * Contains comprehensive information about face liveness detection
17
- */
18
3
  export interface FaceAntiSpoofingResult {
19
- /**
20
- * Neural network confidence score
21
- * Range: 0.0 to 1.0
22
- * Lower values indicate more likely to be live
23
- */
24
4
  neuralNetworkScore: number;
25
-
26
- /**
27
- * Laplacian variance-based image quality score
28
- * Range: 0.0 to 5000+
29
- * Higher values = better image quality
30
- * Used to distinguish blur from spoofing
31
- */
32
5
  laplacianScore: number;
33
-
34
- /**
35
- * Combined weighted score from multiple models
36
- * Range: 0.0 to 1.0
37
- * Provides robust detection by ensemble voting
38
- */
39
6
  combinedScore: number;
40
-
41
- /**
42
- * Derived score used with the configured liveness thresholds
43
- */
44
7
  confidence: number;
45
8
  }
46
9
 
47
- /**
48
- * Face rectangle/bounds information
49
- */
50
10
  export interface FaceRect {
51
- /** X coordinate in pixels */
52
11
  x: number;
53
- /** Y coordinate in pixels */
54
12
  y: number;
55
- /** Face width in pixels */
56
13
  width: number;
57
- /** Face height in pixels */
58
14
  height: number;
59
15
  }
60
16
 
@@ -62,420 +18,62 @@ export interface SpoofDetectedFace {
62
18
  bounds: FaceRect;
63
19
  }
64
20
 
65
- // ============================================================================
66
- // Anti-spoofing State & Configuration
67
- // ============================================================================
68
-
69
- /**
70
- * Anti-spoofing detection state
71
- */
72
- export interface AntiSpoofState {
73
- /** Confidence score (0.0-1.0) */
74
- confidence: number;
75
- /** Consecutive frames detected as live */
76
- consecutiveLiveFrames: number;
77
- /** Last detection result */
78
- lastResult: FaceAntiSpoofingResult | null;
79
- /** Whether face is single and detected */
80
- hasSingleFace: boolean;
81
- /** Whether face is centered in frame */
82
- isFaceCentered: boolean;
83
- }
84
-
85
- /**
86
- * Face tracking state
87
- */
88
- export interface FaceTrackingState {
89
- lastX: number;
90
- lastY: number;
91
- lastW: number;
92
- lastH: number;
93
- stableCount: number;
94
- }
95
-
96
- /**
97
- * Liveness detection state
98
- */
99
- export interface LivenessState {
100
- level: number;
101
- step: number;
102
- blinkCount: number;
103
- }
104
-
105
- /**
106
- * Complete shared state for frame processing
107
- */
108
- export interface SharedFrameProcessorState {
109
- lastProcessedTime: number;
110
- faceTracking: FaceTrackingState;
111
- flags: {
112
- captured: boolean;
113
- showCodeScanner: boolean;
114
- isActive: boolean;
115
- hasSingleFace: boolean;
116
- isFaceCentered: boolean;
117
- eyeClosed: boolean;
118
- };
119
- liveness: LivenessState;
120
- antiSpoof: AntiSpoofState;
121
- centering: {
122
- centeredFrames: number;
123
- frameWidth: number;
124
- frameHeight: number;
125
- };
126
- performance: {
127
- batchCounter: number;
128
- lastBatchUpdate: number;
129
- };
130
- }
131
-
132
- /**
133
- * Face detection update callback data
134
- */
135
- export interface FacesUpdateData {
136
- count: number;
137
- progress: number;
138
- step: number;
139
- isCentered: boolean;
140
- antiSpoofState: AntiSpoofState;
141
- }
142
-
143
- /**
144
- * Anti-spoof update callback data
145
- */
146
- export interface OnAntiSpoofUpdateData {
147
- confidence: number;
148
- rawResult?: FaceAntiSpoofingResult;
149
- consecutiveLiveFrames: number;
150
- isFaceCentered: boolean;
151
- }
152
-
153
- // ============================================================================
154
- // Hook Configuration
155
- // ============================================================================
156
-
157
- /**
158
- * Configuration options for useFaceDetectionFrameProcessor hook
159
- */
160
- export interface UseFaceDetectionFrameProcessorOptions {
161
- /**
162
- * Callback when a stable, live face is detected
163
- * @param faceRect - Face position and size
164
- * @param antiSpoofResult - Anti-spoofing detection result
165
- */
166
- onStableFaceDetected?: (
167
- faceRect: FaceRect,
168
- antiSpoofResult?: FaceAntiSpoofingResult
169
- ) => void;
170
-
171
- /**
172
- * Callback for face updates during detection
173
- * Called periodically with detection progress
174
- */
175
- onFacesUpdate?: (data: FacesUpdateData) => void;
176
-
177
- /**
178
- * Callback for liveness verification updates
179
- * @param step - Liveness step (0-2)
180
- * @param extra - Additional data like blink count
181
- */
182
- onLivenessUpdate?: (step: number, extra?: Record<string, any>) => void;
183
-
184
- /**
185
- * Callback for anti-spoof detection updates
186
- * Called when anti-spoofing detection result changes
187
- */
188
- onAntiSpoofUpdate?: (result: OnAntiSpoofUpdateData) => void;
189
-
190
- /**
191
- * Show code scanner overlay
192
- * @default false
193
- */
194
- showCodeScanner?: boolean;
195
-
196
- /**
197
- * Loading state - pauses frame processing
198
- * @default false
199
- */
200
- isLoading?: boolean;
201
-
202
- /**
203
- * Enable/disable frame processing
204
- * @default true
205
- */
206
- isActive?: boolean;
207
-
208
- /**
209
- * Liveness verification level
210
- * @values 0 - Anti-spoofing only (fast)
211
- * @values 1 - Anti-spoofing + blink detection (more thorough)
212
- * @default 0
213
- */
214
- livenessLevel?: number;
215
-
216
- /**
217
- * Anti-spoofing confidence threshold
218
- * Range: 0.0 - 1.0
219
- * Lower values = more lenient, higher values = stricter
220
- * @default 0.35
221
- */
222
- antispooflevel?: number;
223
- }
224
-
225
- /**
226
- * Return value from useFaceDetectionFrameProcessor hook
227
- */
228
- export interface UseFaceDetectionFrameProcessorReturn {
229
- /**
230
- * Frame processor function for Vision Camera
231
- */
232
- frameProcessor: FrameProcessor;
233
-
234
- /**
235
- * Reset capture state to initial values
236
- */
237
- resetCaptureState: () => void;
238
-
239
- /**
240
- * Force reset all states including shared values
241
- */
242
- forceResetCaptureState: () => void;
243
-
244
- /**
245
- * Update code scanner visibility
246
- */
247
- updateShowCodeScanner: (value: boolean) => void;
248
-
249
- /**
250
- * Update processing active state
251
- */
252
- updateIsActive: (active: boolean) => void;
253
-
254
- /**
255
- * Initialize anti-spoofing module
256
- */
257
- initializeAntiSpoof: () => Promise<boolean>;
258
-
259
- /**
260
- * Shared value for capture state
261
- * Use .value to access: capturedSV.value.value
262
- */
263
- capturedSV: SharedValue<boolean>;
264
-
265
- /**
266
- * Current anti-spoofing detection state
267
- */
268
- antiSpoofState: AntiSpoofState;
269
- }
270
-
271
- /**
272
- * VisionCamera 5 frame-output options for spoof detection.
273
- * The callback runs on the React Native runtime after native inference.
274
- */
275
- export interface UseFaceAntiSpoofFrameOutputOptions extends Partial<FrameOutputOptions> {
21
+ export interface UseFaceAntiSpoofFrameOutputOptions {
276
22
  antispoofLevel?: number;
277
23
  stableFrames?: number;
278
24
  requiredLiveFrames?: number;
279
25
  laplacianThreshold?: number;
280
26
  maxNeuralSpoofScore?: number;
281
- onResult?: (result: FaceAntiSpoofingResult) => void;
282
27
  onFacesDetected?: (faces: SpoofDetectedFace[]) => void;
283
- onStableFaceDetected?: (face: FaceRect, result: FaceAntiSpoofingResult) => void;
28
+ onResult?: (result: FaceAntiSpoofingResult) => void;
29
+ onStableFaceDetected?: (
30
+ face: FaceRect,
31
+ result: FaceAntiSpoofingResult,
32
+ ) => void;
284
33
  onError?: (error: Error) => void;
285
34
  }
286
35
 
287
- /** Create a VisionCamera 5 frame output backed by the native detector. */
288
- export function useFaceAntiSpoofFrameOutput(
289
- options?: UseFaceAntiSpoofFrameOutputOptions,
290
- ): CameraFrameOutput;
291
-
292
- export function resetFaceAntiSpoofFrameOutput(output: CameraFrameOutput): void;
293
-
294
- // ============================================================================
295
- // Module Functions
296
- // ============================================================================
297
-
298
- /**
299
- * Frame processor function for real-time face anti-spoofing detection
300
- * Call within a Vision Camera frame processor
301
- *
302
- * @example
303
- * ```typescript
304
- * const frameProcessor = useFrameProcessor((frame) => {
305
- * 'worklet';
306
- * const result = faceAntiSpoofFrameProcessor(frame);
307
- * if (result && result.confidence > 0.5) {
308
- * // Evaluate confidence together with neuralNetworkScore and laplacianScore.
309
- * }
310
- * }, []);
311
- * ```
312
- *
313
- * @param frame - Vision Camera frame object
314
- * @returns Detection result or null if no face detected
315
- */
316
- export function faceAntiSpoofFrameProcessor(
317
- frame: Frame
318
- ): FaceAntiSpoofingResult | null;
319
-
320
- /**
321
- * Check if face anti-spoofing module is available on device
322
- * Call before attempting to use the module
323
- *
324
- * @returns true if module is available, false otherwise
325
- */
326
- export function isFaceAntiSpoofAvailable(): boolean;
327
-
328
- /**
329
- * Initialize the face anti-spoofing module
330
- * Must be called before using the frame processor
331
- *
332
- * @returns Promise<boolean> - true if initialization successful
333
- *
334
- * @example
335
- * ```typescript
336
- * useEffect(() => {
337
- * initializeFaceAntiSpoof()
338
- * .then(success => {
339
- * if (success) {
340
- * console.log('Anti-spoof ready');
341
- * }
342
- * });
343
- * }, []);
344
- * ```
345
- */
346
- export function initializeFaceAntiSpoof(): Promise<boolean>;
347
-
348
- /**
349
- * Custom React Native hook for comprehensive face detection with anti-spoofing
350
- * Provides advanced features like blink detection and face centering
351
- *
352
- * @param options - Configuration options
353
- * @returns Hook return value with frame processor and callbacks
354
- *
355
- * @example
356
- * ```typescript
357
- * const { frameProcessor, resetCaptureState, antiSpoofState } =
358
- * useFaceDetectionFrameProcessor({
359
- * livenessLevel: 1,
360
- * antispooflevel: 0.35,
361
- * onStableFaceDetected: (rect, result) => {
362
- * console.log('Capture complete!', rect);
363
- * },
364
- * });
365
- * ```
366
- */
367
- export function useFaceDetectionFrameProcessor(
368
- options: UseFaceDetectionFrameProcessorOptions
369
- ): UseFaceDetectionFrameProcessorReturn;
370
-
371
- // ============================================================================
372
- // Accelerator Types
373
- // ============================================================================
374
-
375
- /**
376
- * TensorFlow Lite accelerator type
377
- * Determines which hardware is used for inference
378
- */
379
- export type AcceleratorType = 'CPU' | 'GPU' | 'NNAPI';
380
-
381
- /**
382
- * Module information
383
- */
384
- export interface ModuleInfo {
385
- /** Module name */
386
- name: string;
387
- /** Available API methods */
388
- methods: string[];
389
- /** Module version */
390
- version: string;
391
- /** Active accelerator (if available) */
392
- accelerator?: AcceleratorType;
393
- }
394
-
395
- /**
396
- * Model status information
397
- */
398
- export interface ModelStatus {
399
- /** Whether plugin is available on this device */
36
+ export interface FaceAntiSpoofModelStatus {
400
37
  pluginAvailable: boolean;
401
- /** Whether TensorFlow Lite model is loaded */
402
38
  modelLoaded: boolean;
403
- /** Active accelerator type */
404
- accelerator?: AcceleratorType;
39
+ moduleInitialized: boolean;
405
40
  }
406
41
 
407
- // ============================================================================
408
- // Native Module Interface
409
- // ============================================================================
42
+ export interface FaceAntiSpoofModuleInfo {
43
+ name: string;
44
+ methods: string[];
45
+ accelerators?: string[];
46
+ }
410
47
 
411
- /**
412
- * Native module interface for advanced use cases
413
- * Generally not needed - use the exported functions instead
414
- */
415
48
  export interface FaceAntiSpoofModule {
416
- /**
417
- * Initialize native module
418
- */
419
49
  initialize(): Promise<boolean>;
420
-
421
- /**
422
- * Check model loading status
423
- */
424
- checkModelStatus(): Promise<ModelStatus>;
425
-
426
- /**
427
- * Check module availability
428
- */
50
+ checkModelStatus(): Promise<FaceAntiSpoofModelStatus>;
429
51
  isAvailable(): Promise<boolean>;
430
-
431
- /**
432
- * Test connection to native module
433
- */
434
52
  testMethod(): Promise<string>;
435
-
436
- /**
437
- * Get module information
438
- */
439
- getModuleInfo(): Promise<ModuleInfo>;
440
-
441
- /**
442
- * Install/setup native dependencies
443
- */
53
+ getModuleInfo(): Promise<FaceAntiSpoofModuleInfo>;
444
54
  install(): Promise<boolean>;
55
+ processFrame?(
56
+ frameData: number[][],
57
+ width: number,
58
+ height: number,
59
+ rowStrides: number[],
60
+ pixelStrides: number[],
61
+ ): Promise<FaceAntiSpoofingResult>;
62
+ cleanup?(): Promise<boolean>;
63
+ getAccelerator?(): Promise<string>;
445
64
  }
446
65
 
447
- /**
448
- * Native module instance
449
- */
450
- declare const FaceAntiSpoof: FaceAntiSpoofModule;
451
-
452
- export default FaceAntiSpoof;
453
-
454
- // ============================================================================
455
- // Constants
456
- // ============================================================================
457
-
458
- /**
459
- * Default anti-spoofing confidence threshold
460
- */
461
- export const DEFAULT_ANTI_SPOOF_LEVEL = 0.35;
66
+ export declare function useFaceAntiSpoofFrameOutput(
67
+ options?: UseFaceAntiSpoofFrameOutputOptions,
68
+ ): CameraOutput;
462
69
 
463
- /**
464
- * Default face stability threshold (frames)
465
- */
466
- export const DEFAULT_FACE_STABILITY_THRESHOLD = 3;
70
+ export declare function resetFaceAntiSpoofFrameOutput(
71
+ output: CameraOutput,
72
+ ): void;
467
73
 
468
- /**
469
- * Default face movement threshold (pixels)
470
- */
471
- export const DEFAULT_FACE_MOVEMENT_THRESHOLD = 15;
74
+ export declare function isFaceAntiSpoofAvailable(): boolean;
472
75
 
473
- /**
474
- * Minimum required blinks for liveness verification
475
- */
476
- export const DEFAULT_REQUIRED_BLINKS = 3;
76
+ export declare function initializeFaceAntiSpoof(): Promise<boolean>;
477
77
 
478
- /**
479
- * Blink detection threshold (eye closure probability)
480
- */
481
- export const DEFAULT_BLINK_THRESHOLD = 0.3;
78
+ declare const FaceAntiSpoof: FaceAntiSpoofModule | undefined;
79
+ export default FaceAntiSpoof;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-vision-camera-spoof-detector",
3
- "version": "1.3.6",
3
+ "version": "1.3.7",
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": {