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.
- package/LICENSE +21 -0
- package/README.md +138 -220
- 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
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
.
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
-
|
|
126
|
-
-
|
|
127
|
-
-
|
|
128
|
-
-
|
|
129
|
-
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
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.
|
|
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/
|
|
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
|
+
}
|