react-native-vision-camera-spoof-detector 1.4.1 → 1.5.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 +16 -29
- package/android/build.gradle +0 -13
- package/android/src/main/java/com/faceantispoof/FaceAntiSpoofPackage.kt +1 -3
- package/android/src/main/java/com/faceantispoof/FaceAntiSpoofingAdvanced.kt +78 -925
- package/android/src/main/java/com/lengdev/livenessdetector/LivenessDetector.kt +228 -0
- package/android/src/main/java/com/margelo/nitro/camera/spoofdetector/HybridSpoofDetectorOutput.kt +17 -31
- package/android/src/main/jniLibs/arm64-v8a/libliveness_detector.so +0 -0
- package/android/src/main/jniLibs/armeabi-v7a/libliveness_detector.so +0 -0
- package/index.d.ts +2 -9
- package/index.js +6 -6
- package/ios/FaceAntiSpoofModule.m +3 -2
- package/ios/HybridSpoofDetectorOutput.swift +3 -3
- package/lib/assets/live/config.json +1 -0
- package/lib/assets/live/model_1.bin +0 -0
- package/lib/assets/live/model_1.param +214 -0
- package/lib/assets/live/model_2.bin +0 -0
- package/lib/assets/live/model_2.param +238 -0
- package/nitrogen/generated/android/c++/JSpoofDetectorOutputOptions.hpp +1 -9
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/camera/spoofdetector/SpoofDetectorOutputOptions.kt +4 -14
- package/nitrogen/generated/ios/swift/SpoofDetectorOutputOptions.swift +1 -37
- package/nitrogen/generated/shared/c++/SpoofDetectorOutputOptions.hpp +1 -9
- package/package.json +1 -2
- package/src/specs/SpoofDetectorFactory.nitro.ts +0 -2
- package/android/fix-prefab.gradle +0 -4
- package/android/src/main/java/com/faceantispoof/AcceleratorConfig.kt +0 -97
- package/android/src/main/java/com/faceantispoof/FaceAntiSpoofModule.kt +0 -242
- package/android/src/main/res/values/strings.xml +0 -3
- package/lib/assets/FaceAntiSpoofing.tflite +0 -0
- package/lib/assets/model_spec.json +0 -16
package/README.md
CHANGED
|
@@ -3,13 +3,13 @@
|
|
|
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
|
-
Face anti-spoofing and liveness scoring for React Native Vision Camera 5. A Nitro-backed native camera output detects eligible faces
|
|
6
|
+
Face anti-spoofing and liveness scoring for React Native Vision Camera 5. A Nitro-backed native camera output detects eligible faces and reports liveness scores to JavaScript. Android uses the source dual-model NCNN detector with CameraX YUV input; iOS uses its existing TensorFlow Lite pipeline.
|
|
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
|
-
-
|
|
12
|
+
- Dual-model NCNN inference on Android and TensorFlow Lite inference with Metal/CPU on iOS
|
|
13
13
|
- Native face detection (ML Kit on Android, Vision on iOS); no separate face-detector output is needed
|
|
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
|
|
@@ -24,7 +24,7 @@ Face anti-spoofing and liveness scoring for React Native Vision Camera 5. A Nitr
|
|
|
24
24
|
- `react-native-worklets` `^0.12.0`
|
|
25
25
|
- `react-native-vision-camera-worklets` `^5.0.0`
|
|
26
26
|
- iOS 15.5 or later
|
|
27
|
-
- Android support through the package's native modules and bundled
|
|
27
|
+
- Android support through the package's native modules and bundled NCNN models
|
|
28
28
|
|
|
29
29
|
## Installation
|
|
30
30
|
|
|
@@ -91,7 +91,7 @@ export default function AntiSpoofScreen() {
|
|
|
91
91
|
|
|
92
92
|
const antiSpoofOutput = useFaceAntiSpoofFrameOutput({
|
|
93
93
|
onResult(result) {
|
|
94
|
-
console.log('
|
|
94
|
+
console.log('liveness score (0 = spoof, 1 = live):', result);
|
|
95
95
|
},
|
|
96
96
|
onError(error) {
|
|
97
97
|
console.warn('anti-spoof error:', error);
|
|
@@ -136,7 +136,7 @@ const styles = StyleSheet.create({
|
|
|
136
136
|
});
|
|
137
137
|
```
|
|
138
138
|
|
|
139
|
-
The output is processed natively; the hook returns a `CameraOutput` for Vision Camera's `outputs` array. `onResult` and `onFacesDetected` are called for every processed frame. `onStableFaceDetected` fires once when its face-stability and liveness gates pass; reset it with `resetFaceAntiSpoofFrameOutput` to allow another stable-face callback.
|
|
139
|
+
The output is processed natively; the hook returns a `CameraOutput` for Vision Camera's `outputs` array. `onResult` and `onFacesDetected` are called for every processed frame. `onResult` receives a liveness score from `0.0` (spoof) to `1.0` (live). `onStableFaceDetected` fires once when its face-stability and liveness gates pass and receives the latest liveness score; reset it with `resetFaceAntiSpoofFrameOutput` to allow another stable-face callback.
|
|
140
140
|
|
|
141
141
|
## API reference
|
|
142
142
|
|
|
@@ -160,29 +160,22 @@ Returned value should be included in the `Camera` component `outputs` array.
|
|
|
160
160
|
Options:
|
|
161
161
|
|
|
162
162
|
```ts
|
|
163
|
+
type FaceAntiSpoofingResult = number;
|
|
164
|
+
|
|
163
165
|
interface UseFaceAntiSpoofFrameOutputOptions {
|
|
164
166
|
antispoofLevel?: number;
|
|
165
167
|
stableFrames?: number;
|
|
166
168
|
requiredLiveFrames?: number;
|
|
167
|
-
laplacianThreshold?: number;
|
|
168
|
-
maxNeuralSpoofScore?: number;
|
|
169
169
|
onFacesDetected?: (faces: SpoofDetectedFace[]) => void;
|
|
170
170
|
onResult?: (result: FaceAntiSpoofingResult) => void;
|
|
171
171
|
onStableFaceDetected?: (face: SpoofDetectedFace['bounds'], result: FaceAntiSpoofingResult) => void;
|
|
172
172
|
onError?: (error: Error) => void;
|
|
173
173
|
}
|
|
174
|
-
|
|
175
|
-
interface FaceAntiSpoofingResult {
|
|
176
|
-
neuralNetworkScore: number;
|
|
177
|
-
laplacianScore: number;
|
|
178
|
-
combinedScore: number;
|
|
179
|
-
confidence: number;
|
|
180
|
-
}
|
|
181
174
|
```
|
|
182
175
|
|
|
183
176
|
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.
|
|
184
177
|
|
|
185
|
-
`onFacesDetected` is optional and receives eligible faces as `{ bounds: { x, y, width, height } }`. `onResult` receives numeric
|
|
178
|
+
`onFacesDetected` is optional and receives eligible faces as `{ bounds: { x, y, width, height } }`. `onResult` receives a numeric liveness score between `0.0` (spoof) and `1.0` (live); use the score with 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 score. This event is not a guarantee against presentation attacks.
|
|
186
179
|
|
|
187
180
|
Default output options on both platforms:
|
|
188
181
|
|
|
@@ -191,8 +184,6 @@ Default output options on both platforms:
|
|
|
191
184
|
| `antispoofLevel` | `0.4` | Minimum confidence for a frame to count toward the live-frame streak |
|
|
192
185
|
| `stableFrames` | `3` | Eligible face frames required before stable-face notification |
|
|
193
186
|
| `requiredLiveFrames` | `3` | Consecutive score-passing frames required before notification |
|
|
194
|
-
| `laplacianThreshold` | `1100` | Minimum Laplacian score for a frame to pass |
|
|
195
|
-
| `maxNeuralSpoofScore` | `0.1` | Neural scores at or above this value fail the liveness gate |
|
|
196
187
|
|
|
197
188
|
Vision 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.
|
|
198
189
|
|
|
@@ -232,21 +223,16 @@ Returns `boolean`.
|
|
|
232
223
|
|
|
233
224
|
### `FaceAntiSpoofingResult`
|
|
234
225
|
|
|
235
|
-
|
|
236
|
-
Result fields:
|
|
237
|
-
|
|
238
|
-
- `neuralNetworkScore`: raw model score from the TFLite classifier
|
|
239
|
-
- `laplacianScore`: image variance / quality score used to detect blur or non-real textures
|
|
240
|
-
- `combinedScore`: combined weighted score constructed by the native implementation
|
|
241
|
-
- `confidence`: score used with the configured thresholds; not a calibrated probability
|
|
226
|
+
`FaceAntiSpoofingResult` is a number between `0.0` (spoof) and `1.0` (live). On Android this is the score returned by the dual-model NCNN liveness detector. On iOS this is the existing TFLite pipeline's combined confidence score. Values are model scores, not calibrated probabilities.
|
|
242
227
|
|
|
243
228
|
## Android and iOS implementation notes
|
|
244
229
|
|
|
245
230
|
### Android
|
|
246
231
|
|
|
247
|
-
- Uses CameraX `ImageAnalysis`, ML Kit face detection, and the bundled
|
|
248
|
-
-
|
|
249
|
-
- Uses
|
|
232
|
+
- Uses CameraX `ImageAnalysis`, ML Kit face detection, and the bundled dual-model NCNN liveness detector
|
|
233
|
+
- Packs CameraX YUV planes into NV21 for the native liveness detector
|
|
234
|
+
- Uses CPU inference on `arm64-v8a` and `armeabi-v7a`
|
|
235
|
+
- Uses YUV input, a brightness gate, face-size/frame-margin/pose/landmark checks, and the NCNN detector's preprocessing
|
|
250
236
|
- Uses `MirrorMode.AUTO` and Vision Camera's selected analysis resolution
|
|
251
237
|
|
|
252
238
|
### iOS
|
|
@@ -276,13 +262,14 @@ if (!isFaceAntiSpoofAvailable()) {
|
|
|
276
262
|
|
|
277
263
|
- Confirm the app has camera permissions
|
|
278
264
|
- Ensure the module is properly linked in the app project
|
|
279
|
-
-
|
|
265
|
+
- The NCNN liveness engine is bundled for `arm64-v8a` and `armeabi-v7a`
|
|
266
|
+
- Check native logs for model-loading errors
|
|
280
267
|
|
|
281
268
|
## Platform support
|
|
282
269
|
|
|
283
270
|
| Platform | GPU acceleration | Status | Notes |
|
|
284
271
|
|----------|------------------|--------|-------|
|
|
285
|
-
| Android |
|
|
272
|
+
| Android | ❌ No | ✅ Supported | Dual-model NCNN CPU inference on ARM ABIs |
|
|
286
273
|
| iOS | ✅ Yes | ✅ Supported | Uses TensorFlow Lite Metal GPU delegate when available, with CPU fallback |
|
|
287
274
|
| Web | ❌ No | ❌ Not supported | Native camera processing only |
|
|
288
275
|
|
package/android/build.gradle
CHANGED
|
@@ -36,7 +36,6 @@ android {
|
|
|
36
36
|
versionCode 1
|
|
37
37
|
versionName "1.0"
|
|
38
38
|
|
|
39
|
-
buildConfigField "String", "MODEL_FILE", "\"FaceAntiSpoofing.tflite\""
|
|
40
39
|
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
|
|
41
40
|
}
|
|
42
41
|
|
|
@@ -65,10 +64,6 @@ android {
|
|
|
65
64
|
}
|
|
66
65
|
}
|
|
67
66
|
|
|
68
|
-
aaptOptions {
|
|
69
|
-
noCompress "tflite"
|
|
70
|
-
}
|
|
71
|
-
|
|
72
67
|
packagingOptions {
|
|
73
68
|
resources.excludes.addAll([
|
|
74
69
|
'META-INF/DEPENDENCIES',
|
|
@@ -132,14 +127,6 @@ dependencies {
|
|
|
132
127
|
// Kotlin
|
|
133
128
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
|
|
134
129
|
|
|
135
|
-
// TensorFlow Lite (includes NNAPI support built-in)
|
|
136
|
-
implementation "org.tensorflow:tensorflow-lite:2.17.0"
|
|
137
|
-
implementation "org.tensorflow:tensorflow-lite-support:0.5.0"
|
|
138
|
-
|
|
139
|
-
// GPU Delegate for TensorFlow Lite
|
|
140
|
-
implementation "org.tensorflow:tensorflow-lite-gpu:2.17.0"
|
|
141
|
-
implementation "org.tensorflow:tensorflow-lite-gpu-api:2.17.0"
|
|
142
|
-
|
|
143
130
|
// Kotlin Coroutines
|
|
144
131
|
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3"
|
|
145
132
|
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3"
|
|
@@ -4,11 +4,9 @@ import com.facebook.react.BaseReactPackage
|
|
|
4
4
|
import com.facebook.react.bridge.NativeModule
|
|
5
5
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
6
|
import com.facebook.react.module.model.ReactModuleInfoProvider
|
|
7
|
-
import com.faceantispoof.FaceAntiSpoofModule
|
|
8
7
|
|
|
9
8
|
class FaceAntiSpoofPackage : BaseReactPackage() {
|
|
10
|
-
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? =
|
|
11
|
-
if (name == FaceAntiSpoofModule.NAME) FaceAntiSpoofModule(reactContext) else null
|
|
9
|
+
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? = null
|
|
12
10
|
|
|
13
11
|
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider = ReactModuleInfoProvider {
|
|
14
12
|
HashMap()
|