react-native-vision-camera-spoof-detector 1.0.17 → 1.0.18

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/LICENSE +21 -0
  2. package/README.md +138 -220
  3. package/package.json +3 -7
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ License
2
+
3
+ Copyright (c) 2024 JESCON TECHNOLOGIES PVT LTD
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,220 +1,138 @@
1
- # React Native Vision Camera Face Anti-Spoofing Detector
2
-
3
- [![npm version](https://img.shields.io/npm/v/react-native-vision-camera-spoof-detector.svg)](https://www.npmjs.com/package/react-native-vision-camera-spoof-detector)
4
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
-
6
- High-performance **face anti-spoofing and liveness detection** module for React Native with Vision Camera integration. Uses TensorFlow Lite with GPU acceleration for real-time detection.
7
-
8
- ## Features
9
-
10
- ✅ **Real-time Face Liveness Detection** - Distinguish between live faces and spoofed images/videos
11
- ✅ **GPU Acceleration** - TensorFlow Lite GPU delegate support
12
- **NNAPI Support** - Hardware acceleration fallback for older devices
13
- ✅ **Multi-Threading** - Non-blocking background processing
14
- ✅ **Optimized YUV Processing** - Direct frame processing without Bitmap conversion
15
- **TypeScript Support** - Full type definitions included
16
- **Lightweight** - Only 20.92 MB (optimized build)
17
- **Production Ready** - Tested and stable
18
-
19
- ## Installation
20
-
21
- ```bash
22
- npm install react-native-vision-camera-spoof-detector
23
- # or
24
- yarn add react-native-vision-camera-spoof-detector
25
- ```
26
-
27
- ### Peer Dependencies
28
-
29
- This module requires the following peer dependencies:
30
-
31
- ```bash
32
- npm install react-native-vision-camera react-native-reanimated react-native-worklets-core
33
- ```
34
-
35
- ## Quick Start
36
-
37
- ### 1. Initialize the Module
38
-
39
- ```javascript
40
- import { initializeFaceAntiSpoof } from 'react-native-vision-camera-spoof-detector';
41
-
42
- // In your app initialization
43
- useEffect(() => {
44
- initializeFaceAntiSpoof()
45
- .then(() => console.log('Face anti-spoof initialized'))
46
- .catch(err => console.error('Init failed:', err));
47
- }, []);
48
- ```
49
-
50
- ### 2. Use in Frame Processor
51
-
52
- ```javascript
53
- import { useFrameProcessor } from 'react-native-vision-camera';
54
- import { faceAntiSpoofFrameProcessor } from 'react-native-vision-camera-spoof-detector';
55
-
56
- export function CameraScreen() {
57
- const frameProcessor = useFrameProcessor((frame) => {
58
- 'worklet';
59
-
60
- const result = runAsync(frame, () => {
61
- 'worklet';
62
- return faceAntiSpoofFrameProcessor(frame);
63
- });
64
-
65
- // Use the result
66
- if (result?.isLive) {
67
- console.log('Live face detected:', result.label);
68
- }
69
- }, []);
70
-
71
- return (
72
- <Camera
73
- device={device}
74
- frameProcessor={frameProcessor}
75
- // ... other props
76
- />
77
- );
78
- }
79
- ```
80
-
81
- ## API Reference
82
-
83
- ### `initializeFaceAntiSpoof(): Promise<boolean>`
84
-
85
- Initializes the face anti-spoofing module. Must be called before using the frame processor.
86
-
87
- **Returns:** `Promise<boolean>` - true if initialization was successful
88
-
89
- ```javascript
90
- const isInitialized = await initializeFaceAntiSpoof();
91
- ```
92
-
93
- ### `faceAntiSpoofFrameProcessor(frame): FaceAntiSpoofingResult | null`
94
-
95
- Process a camera frame for face anti-spoofing detection.
96
-
97
- **Parameters:**
98
- - `frame` (Frame) - Vision Camera frame object
99
-
100
- **Returns:**
101
- ```typescript
102
- {
103
- isLive: boolean; // true if face is live
104
- label: string; // "Live Face" or "Spoof Face"
105
- neuralNetworkScore: number; // 0.0-1.0 (lower = more likely live)
106
- laplacianScore: number; // Image quality metric
107
- combinedScore: number; // 0.0-1.0 weighted score
108
- error?: string; // Error message if any
109
- }
110
- ```
111
-
112
- ### `isFaceAntiSpoofAvailable(): boolean`
113
-
114
- Check if the native module is available.
115
-
116
- ```javascript
117
- const available = isFaceAntiSpoofAvailable();
118
- ```
119
-
120
- ## Performance
121
-
122
- ### Optimization Techniques
123
-
124
- - **Multi-Threading**: Heavy processing runs on a dedicated background thread, keeping camera smooth
125
- - **GPU Acceleration**: Uses TensorFlow Lite GPU delegate when available
126
- - **NNAPI Support**: Falls back to NNAPI for hardware acceleration on older devices
127
- - **YUV Direct Processing**: No Bitmap conversion - works directly with camera frame data
128
- - **Reusable Buffers**: Allocates buffers once, reuses for each frame
129
- - **Single-Frame Processing**: Only processes one frame at a time to prevent queue overflow
130
-
131
- ### Benchmark
132
-
133
- | Metric | Value |
134
- |--------|-------|
135
- | Processing Time | ~50-100ms per frame |
136
- | Memory Usage | <30 MB (runtime) |
137
- | Package Size | 20.92 MB |
138
- | Support | Android 21+ |
139
-
140
- ## Architecture
141
-
142
- ```
143
- VisionCamera (30fps callback)
144
-
145
- faceAntiSpoofFrameProcessor()
146
-
147
- Submit to background executor
148
-
149
- Non-blocking return
150
-
151
- Latest result available
152
- ```
153
-
154
- Processing happens on:
155
- - Single-threaded `Executors.newSingleThreadExecutor()`
156
- - Daemon thread for proper lifecycle
157
- - Non-blocking callback returns immediately
158
-
159
- ## Configuration
160
-
161
- ### Accelerator Types
162
-
163
- The module automatically selects the best available accelerator:
164
-
165
- 1. **GPU** - TensorFlow Lite GPU delegate (fastest)
166
- 2. **NNAPI** - Android Neural Networks API
167
- 3. **CPU** - Fallback for older devices
168
-
169
- Check which accelerator is in use:
170
-
171
- ```javascript
172
- import FaceAntiSpoof from 'react-native-vision-camera-spoof-detector';
173
-
174
- FaceAntiSpoof.checkModelStatus()
175
- .then(status => console.log('Accelerator:', status.accelerator));
176
- ```
177
-
178
- ## Troubleshooting
179
-
180
- ### Module Not Available
181
-
182
- ```javascript
183
- if (!isFaceAntiSpoofAvailable()) {
184
- console.error('Face anti-spoof not available on this device');
185
- }
186
- ```
187
-
188
- ### Initialization Fails
189
-
190
- ```javascript
191
- try {
192
- await initializeFaceAntiSpoof();
193
- } catch (error) {
194
- console.error('Init error:', error.message);
195
- }
196
- ```
197
-
198
- ### Frame Processing Too Slow
199
-
200
- - Ensure you're using a physical device (emulators are slow)
201
- - Check if GPU acceleration is working
202
- - Reduce frame processor workload
203
- - Consider skipping some frames
204
-
205
- ## License
206
-
207
- MIT © JESCON TECHNOLOGIES PVT LTD
208
-
209
- ## Support
210
-
211
- For issues and feature requests, visit: [GitHub Issues](https://github.com/jescon-tech/react-native-vision-camera-spoof-detector/issues)
212
-
213
- ## Changelog
214
-
215
- See [CHANGELOG.md](./CHANGELOG.md) for version history and updates.
216
-
217
- ---
218
-
219
- **Package Version:** 1.0.0
220
- **Last Updated:** November 18, 2025
1
+ # react-native-vision-camera-spoof-detector
2
+
3
+ High-performance face anti-spoofing and liveness detection module for React Native Vision Camera. Uses TensorFlow Lite with GPU acceleration and optimized YUV processing.
4
+
5
+ ## Features
6
+
7
+ - **High Accuracy**: Utilizes advanced TensorFlow Lite models for reliable spoof detection.
8
+ - **Real-time Performance**: GPU-accelerated processing ensures smooth frame rates.
9
+ - **Easy Integration**: Seamlessly integrates with `react-native-vision-camera`.
10
+ - **YUV Processing**: Optimized for efficient image data handling.
11
+
12
+ ## Installation
13
+
14
+ ```bash
15
+ npm install react-native-vision-camera-spoof-detector
16
+ # or
17
+ yarn add react-native-vision-camera-spoof-detector
18
+ ```
19
+
20
+ Make sure you have `react-native-vision-camera` installed:
21
+
22
+ ```bash
23
+ npm install react-native-vision-camera
24
+ # or
25
+ yarn add react-native-vision-camera
26
+ ```
27
+
28
+ ## Usage
29
+
30
+ Here's a basic example of how to use the spoof detector with Vision Camera:
31
+
32
+ ```javascript
33
+ import React, { useEffect, useState } from 'react';
34
+ import { StyleSheet, Text, View } from 'react-native';
35
+ import { Camera, useCameraDevices, useFrameProcessor } from 'react-native-vision-camera';
36
+ import { faceAntiSpoofFrameProcessor, initializeFaceAntiSpoof } from 'react-native-vision-camera-spoof-detector';
37
+ import { runOnJS } from 'react-native-reanimated';
38
+
39
+ export default function App() {
40
+ const devices = useCameraDevices();
41
+ const device = devices.front;
42
+ const [spoofResult, setSpoofResult] = useState(null);
43
+
44
+ useEffect(() => {
45
+ // Initialize the module
46
+ initializeFaceAntiSpoof().then((success) => {
47
+ console.log('FaceAntiSpoof initialized:', success);
48
+ });
49
+ }, []);
50
+
51
+ const frameProcessor = useFrameProcessor((frame) => {
52
+ 'worklet';
53
+ const result = faceAntiSpoofFrameProcessor(frame);
54
+ if (result) {
55
+ runOnJS(setSpoofResult)(result);
56
+ }
57
+ }, []);
58
+
59
+ if (device == null) return <Text>Loading...</Text>;
60
+
61
+ return (
62
+ <View style={styles.container}>
63
+ <Camera
64
+ style={StyleSheet.absoluteFill}
65
+ device={device}
66
+ isActive={true}
67
+ frameProcessor={frameProcessor}
68
+ frameProcessorFps={5} // Adjust FPS as needed
69
+ />
70
+ {spoofResult && (
71
+ <View style={styles.resultContainer}>
72
+ <Text style={styles.resultText}>
73
+ Is Live: {spoofResult.isLive ? 'Yes' : 'No'}
74
+ </Text>
75
+ <Text style={styles.resultText}>
76
+ Score: {spoofResult.neuralNetworkScore?.toFixed(2)}
77
+ </Text>
78
+ <Text style={styles.resultText}>
79
+ Label: {spoofResult.label}
80
+ </Text>
81
+ </View>
82
+ )}
83
+ </View>
84
+ );
85
+ }
86
+
87
+ const styles = StyleSheet.create({
88
+ container: {
89
+ flex: 1,
90
+ },
91
+ resultContainer: {
92
+ position: 'absolute',
93
+ bottom: 50,
94
+ left: 0,
95
+ right: 0,
96
+ alignItems: 'center',
97
+ backgroundColor: 'rgba(0,0,0,0.5)',
98
+ padding: 10,
99
+ },
100
+ resultText: {
101
+ color: 'white',
102
+ fontSize: 20,
103
+ fontWeight: 'bold',
104
+ },
105
+ });
106
+ ```
107
+
108
+ ## API
109
+
110
+ ### `initializeFaceAntiSpoof()`
111
+
112
+ Initializes the face anti-spoofing module. Must be called before using the frame processor.
113
+
114
+ - **Returns**: `Promise<boolean>` - `true` if initialization was successful.
115
+
116
+ ### `faceAntiSpoofFrameProcessor(frame)`
117
+
118
+ Processes the camera frame and returns the spoof detection result.
119
+
120
+ - **frame**: The frame object from `react-native-vision-camera`.
121
+ - **Returns**: `FaceAntiSpoofingResult | null`
122
+
123
+ #### `FaceAntiSpoofingResult`
124
+
125
+ - `isLive` (boolean): `true` if the face is real (live), `false` otherwise.
126
+ - `label` (string): "Live Face" or "Spoof Face".
127
+ - `neuralNetworkScore` (number): Confidence score (0.0 to 1.0).
128
+ - `laplacianScore` (number): Image quality score based on Laplacian variance.
129
+ - `combinedScore` (number): Weighted average score.
130
+ - `error` (string, optional): Error message if detection failed.
131
+
132
+ ## Contributing
133
+
134
+ See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
135
+
136
+ ## License
137
+
138
+ JESCON TECHNOLOGIES PVT LTD
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "react-native-vision-camera-spoof-detector",
3
- "version": "1.0.17",
3
+ "version": "1.0.18",
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/jescon-tech/react-native-vision-camera-spoof-detector",
6
6
  "repository": {
7
7
  "type": "git",
8
- "url": "https://github.com/jescon-tech/react-native-vision-camera-spoof-detector.git"
8
+ "url": "https://github.com/dpraful/react-native-vision-camera-spoof-detector.git"
9
9
  },
10
10
  "bugs": {
11
11
  "url": "https://github.com/jescon-tech/react-native-vision-camera-spoof-detector/issues"
@@ -22,7 +22,6 @@
22
22
  "types": "index.d.ts",
23
23
  "files": [
24
24
  "android/",
25
- "ios/",
26
25
  "index.js",
27
26
  "index.d.ts",
28
27
  "README.md"
@@ -60,13 +59,10 @@
60
59
  "@babel/plugin-proposal-nullish-coalescing-operator": "^7.18.6",
61
60
  "@babel/plugin-proposal-optional-chaining": "^7.21.0"
62
61
  },
63
- "dependencies": {
64
- "react-native-geolocation-service": "^5.3.1"
65
- },
66
62
  "engines": {
67
63
  "node": ">=16.0.0",
68
64
  "npm": ">=8.0.0"
69
65
  },
70
66
  "packageManager": "npm@8.0.0",
71
67
  "documentation": "https://github.com/jescon-tech/react-native-vision-camera-spoof-detector/wiki"
72
- }
68
+ }