react-native-vision-camera-spoof-detector 1.4.1 → 1.5.1
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 +42 -46
- package/VisionCameraSpoofDetector.podspec +12 -2
- 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 +73 -158
- package/ios/NcnnLivenessDetector.h +24 -0
- package/ios/NcnnLivenessDetector.mm +248 -0
- package/ios/ncnn.xcframework/Info.plist +27 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/allocator.h +433 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/benchmark.h +28 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/blob.h +33 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/c_api.h +401 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/command.h +111 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/cpu.h +177 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/datareader.h +111 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/expression.h +17 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/gpu.h +566 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/layer.h +212 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/layer_shader_type.h +18 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/layer_shader_type_enum.h +5 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/layer_type.h +19 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/layer_type_enum.h +115 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/mat.h +1868 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/modelbin.h +69 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/ncnn_export.h +43 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/net.h +252 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/option.h +151 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/paramdict.h +66 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/pipeline.h +101 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/pipelinecache.h +71 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/platform.h +372 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/simplemath.h +98 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/simpleocv.h +492 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/simpleomp.h +42 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/simplestl.h +598 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/simplevk.h +2196 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/vulkan_header_fix.h +1674 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Resources/Info.plist +18 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/allocator.h +433 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/benchmark.h +28 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/blob.h +33 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/c_api.h +401 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/command.h +111 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/cpu.h +177 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/datareader.h +111 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/expression.h +17 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/gpu.h +566 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/layer.h +212 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/layer_shader_type.h +18 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/layer_shader_type_enum.h +5 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/layer_type.h +19 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/layer_type_enum.h +115 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/mat.h +1868 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/modelbin.h +69 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/ncnn_export.h +43 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/net.h +252 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/option.h +151 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/paramdict.h +66 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/pipeline.h +101 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/pipelinecache.h +71 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/platform.h +372 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/simplemath.h +98 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/simpleocv.h +492 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/simpleomp.h +42 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/simplestl.h +598 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/simplevk.h +2196 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/vulkan_header_fix.h +1674 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Resources/Info.plist +18 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/ncnn +0 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/allocator.h +433 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/benchmark.h +28 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/blob.h +33 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/c_api.h +401 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/command.h +111 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/cpu.h +177 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/datareader.h +111 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/expression.h +17 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/gpu.h +566 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/layer.h +212 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/layer_shader_type.h +18 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/layer_shader_type_enum.h +5 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/layer_type.h +19 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/layer_type_enum.h +115 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/mat.h +1868 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/modelbin.h +69 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/ncnn_export.h +43 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/net.h +252 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/option.h +151 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/paramdict.h +66 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/pipeline.h +101 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/pipelinecache.h +71 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/platform.h +372 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/simplemath.h +98 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/simpleocv.h +492 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/simpleomp.h +42 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/simplestl.h +598 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/simplevk.h +2196 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/vulkan_header_fix.h +1674 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Resources/Info.plist +18 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/ncnn +0 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/ncnn +0 -0
- package/ios/openmp.xcframework/Info.plist +27 -0
- package/ios/openmp.xcframework/ios-arm64/openmp.framework/Headers/omp.h +521 -0
- package/ios/openmp.xcframework/ios-arm64/openmp.framework/Headers/ompx.h +165 -0
- package/ios/openmp.xcframework/ios-arm64/openmp.framework/Resources/Info.plist +18 -0
- package/ios/openmp.xcframework/ios-arm64/openmp.framework/Versions/A/Headers/omp.h +521 -0
- package/ios/openmp.xcframework/ios-arm64/openmp.framework/Versions/A/Headers/ompx.h +165 -0
- package/ios/openmp.xcframework/ios-arm64/openmp.framework/Versions/A/Resources/Info.plist +18 -0
- package/ios/openmp.xcframework/ios-arm64/openmp.framework/Versions/A/openmp +0 -0
- package/ios/openmp.xcframework/ios-arm64/openmp.framework/Versions/Current/Headers/omp.h +521 -0
- package/ios/openmp.xcframework/ios-arm64/openmp.framework/Versions/Current/Headers/ompx.h +165 -0
- package/ios/openmp.xcframework/ios-arm64/openmp.framework/Versions/Current/Resources/Info.plist +18 -0
- package/ios/openmp.xcframework/ios-arm64/openmp.framework/Versions/Current/openmp +0 -0
- package/ios/openmp.xcframework/ios-arm64/openmp.framework/openmp +0 -0
- 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,15 +3,15 @@
|
|
|
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 dual-model NCNN detector with CameraX YUV input; iOS uses the same dual-model NCNN scoring approach with Vision face detection and BGRA camera frames.
|
|
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 iOS
|
|
13
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
|
|
14
|
+
- Face size, frame-edge, pose, landmark, and brightness checks before inference
|
|
15
15
|
- Optional callbacks for scores, detected faces, stable-face capture, and errors
|
|
16
16
|
- Output reset without recreating the camera output
|
|
17
17
|
- Configurable liveness thresholds; uses Vision Camera's selected analysis resolution
|
|
@@ -24,7 +24,8 @@ 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
|
+
- iOS NCNN inference requires a physical arm64 device; the bundled NCNN frameworks do not include simulator slices
|
|
28
29
|
|
|
29
30
|
## Installation
|
|
30
31
|
|
|
@@ -54,6 +55,10 @@ pod install
|
|
|
54
55
|
cd ..
|
|
55
56
|
```
|
|
56
57
|
|
|
58
|
+
The camera output uses CPU-based dual-model NCNN inference on physical arm64 iOS devices. The supplied NCNN and OpenMP frameworks do not include simulator slices; simulator builds omit NCNN support and cannot run liveness inference.
|
|
59
|
+
|
|
60
|
+
This applies to the Vision Camera output. The separate legacy `FaceAntiSpoof` NativeModule API remains TensorFlow Lite-backed.
|
|
61
|
+
|
|
57
62
|
Add camera permission text to the app Info.plist:
|
|
58
63
|
|
|
59
64
|
```xml
|
|
@@ -91,7 +96,7 @@ export default function AntiSpoofScreen() {
|
|
|
91
96
|
|
|
92
97
|
const antiSpoofOutput = useFaceAntiSpoofFrameOutput({
|
|
93
98
|
onResult(result) {
|
|
94
|
-
console.log('
|
|
99
|
+
console.log('liveness score (0 = spoof, 1 = live):', result);
|
|
95
100
|
},
|
|
96
101
|
onError(error) {
|
|
97
102
|
console.warn('anti-spoof error:', error);
|
|
@@ -136,7 +141,7 @@ const styles = StyleSheet.create({
|
|
|
136
141
|
});
|
|
137
142
|
```
|
|
138
143
|
|
|
139
|
-
The output is processed natively; the hook returns a `CameraOutput` for Vision Camera's `outputs` array. `
|
|
144
|
+
The output is processed natively; the hook returns a `CameraOutput` for Vision Camera's `outputs` array. `onFacesDetected` is called after face detection for each analyzed frame and receives the eligible faces (possibly an empty array). `onResult` is called only when inference runs: the frame must pass the brightness check and contain exactly one eligible face. It receives a liveness score from `0.0` (spoof) to `1.0` (live). `onStableFaceDetected` fires once when its face-stability and consecutive-live-score checks pass and receives the latest score; reset it with `resetFaceAntiSpoofFrameOutput` to allow another stable-face callback.
|
|
140
145
|
|
|
141
146
|
## API reference
|
|
142
147
|
|
|
@@ -160,43 +165,34 @@ Returned value should be included in the `Camera` component `outputs` array.
|
|
|
160
165
|
Options:
|
|
161
166
|
|
|
162
167
|
```ts
|
|
168
|
+
type FaceAntiSpoofingResult = number;
|
|
169
|
+
|
|
163
170
|
interface UseFaceAntiSpoofFrameOutputOptions {
|
|
164
171
|
antispoofLevel?: number;
|
|
165
172
|
stableFrames?: number;
|
|
166
173
|
requiredLiveFrames?: number;
|
|
167
|
-
laplacianThreshold?: number;
|
|
168
|
-
maxNeuralSpoofScore?: number;
|
|
169
174
|
onFacesDetected?: (faces: SpoofDetectedFace[]) => void;
|
|
170
175
|
onResult?: (result: FaceAntiSpoofingResult) => void;
|
|
171
176
|
onStableFaceDetected?: (face: SpoofDetectedFace['bounds'], result: FaceAntiSpoofingResult) => void;
|
|
172
177
|
onError?: (error: Error) => void;
|
|
173
178
|
}
|
|
174
|
-
|
|
175
|
-
interface FaceAntiSpoofingResult {
|
|
176
|
-
neuralNetworkScore: number;
|
|
177
|
-
laplacianScore: number;
|
|
178
|
-
combinedScore: number;
|
|
179
|
-
confidence: number;
|
|
180
|
-
}
|
|
181
179
|
```
|
|
182
180
|
|
|
183
|
-
The detector
|
|
181
|
+
The detector runs inference only when exactly one eligible face is present. Android uses ML Kit; iOS uses Apple Vision. Both require the face to be at least 18% of the frame width and height, inside a 2% frame margin, within 25 degrees of frontal yaw and pitch, and to have the required eye, nose, and mouth landmarks. Frames rejected by the brightness or face checks clear the consecutive-live-score streak, and a score below `antispoofLevel` resets that streak. The two NCNN models each use a differently expanded face-bounds crop before resizing it to their configured 80 × 80 input dimensions; the crop is not eye-aligned.
|
|
184
182
|
|
|
185
|
-
`onFacesDetected` is optional and receives eligible faces as `{ bounds: { x, y, width, height } }
|
|
183
|
+
`onFacesDetected` is optional and receives eligible faces as `{ bounds: { x, y, width, height } }`, in camera-frame coordinates. `onResult` receives the mean live-class score from the two NCNN models, between `0.0` (spoof) and `1.0` (live); it is a model score, not a calibrated probability. Use it with a policy calibrated for your application. `onStableFaceDetected` is the event that the configured face-stability and consecutive-live-score checks passed, and receives the face bounds and latest score. This event is not a guarantee against presentation attacks.
|
|
186
184
|
|
|
187
185
|
Default output options on both platforms:
|
|
188
186
|
|
|
189
187
|
| Option | Default | Meaning |
|
|
190
188
|
|---|---:|---|
|
|
191
|
-
| `antispoofLevel` | `0.
|
|
189
|
+
| `antispoofLevel` | `0.5` | Minimum liveness score for a frame to count toward the live-frame streak |
|
|
192
190
|
| `stableFrames` | `3` | Eligible face frames required before stable-face notification |
|
|
193
191
|
| `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
192
|
|
|
197
|
-
Vision Camera selects the analysis resolution. Android uses YUV frames and ML Kit; iOS uses BGRA frames and Vision.
|
|
193
|
+
Vision Camera selects the analysis resolution. Android uses YUV frames and ML Kit; iOS uses BGRA frames and Vision. Both camera outputs use the bundled dual-model NCNN liveness detector, but camera input formats and face-detection implementations differ. Calibrate thresholds on representative devices and presentation-attack data rather than assuming identical score distributions.
|
|
198
194
|
|
|
199
|
-
The brightness
|
|
195
|
+
The brightness check is an image-quality gate, not proof of liveness. The default score threshold and frame counts 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.
|
|
200
196
|
|
|
201
197
|
To clear the stable-face state and allow another `onStableFaceDetected` callback:
|
|
202
198
|
|
|
@@ -208,19 +204,19 @@ resetFaceAntiSpoofFrameOutput(antiSpoofOutput);
|
|
|
208
204
|
|
|
209
205
|
### `initializeFaceAntiSpoof()`
|
|
210
206
|
|
|
211
|
-
Optional
|
|
207
|
+
Optional initializer for the legacy iOS `FaceAntiSpoof` React Native module. The Vision Camera output uses the Nitro native output and loads its NCNN models when inference is first run, so this function is not required before creating the output. The legacy module is separate from the camera output and is not available on Android.
|
|
212
208
|
|
|
213
209
|
```ts
|
|
214
210
|
const initialized = await initializeFaceAntiSpoof();
|
|
215
211
|
```
|
|
216
212
|
|
|
217
|
-
Returns `Promise<boolean
|
|
213
|
+
Returns `Promise<boolean>`; it rejects if the legacy module is unavailable or initialization fails.
|
|
218
214
|
|
|
219
215
|
---
|
|
220
216
|
|
|
221
217
|
### `isFaceAntiSpoofAvailable()`
|
|
222
218
|
|
|
223
|
-
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.
|
|
219
|
+
Checks whether the legacy iOS `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. It returns `false` on platforms where the legacy module is not present; this does not indicate whether the Nitro camera output is available.
|
|
224
220
|
|
|
225
221
|
```ts
|
|
226
222
|
const available = isFaceAntiSpoofAvailable();
|
|
@@ -232,40 +228,38 @@ Returns `boolean`.
|
|
|
232
228
|
|
|
233
229
|
### `FaceAntiSpoofingResult`
|
|
234
230
|
|
|
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
|
|
231
|
+
`FaceAntiSpoofingResult` is a number between `0.0` (spoof) and `1.0` (live). For the Vision Camera output on both platforms, it is the mean live-class score from the dual-model NCNN liveness detector. Values are model scores, not calibrated probabilities. The separate legacy iOS `FaceAntiSpoof` module remains TensorFlow Lite-backed.
|
|
242
232
|
|
|
243
233
|
## Android and iOS implementation notes
|
|
244
234
|
|
|
245
235
|
### Android
|
|
246
236
|
|
|
247
|
-
- Uses CameraX `ImageAnalysis`, ML Kit face detection, and the bundled
|
|
248
|
-
-
|
|
249
|
-
- Uses
|
|
237
|
+
- Uses CameraX `ImageAnalysis`, ML Kit face detection, and the bundled dual-model NCNN liveness detector
|
|
238
|
+
- Packs CameraX YUV planes into NV21 for the native liveness detector
|
|
239
|
+
- Uses CPU inference on `arm64-v8a` and `armeabi-v7a`; no GPU inference is enabled
|
|
240
|
+
- Uses YUV input, a brightness gate, face-size/frame-margin/pose/landmark checks, and the NCNN detector's preprocessing
|
|
250
241
|
- Uses `MirrorMode.AUTO` and Vision Camera's selected analysis resolution
|
|
251
242
|
|
|
252
243
|
### iOS
|
|
253
244
|
|
|
254
|
-
- Uses `AVCaptureVideoDataOutput`, Apple Vision face/landmark detection, and the bundled
|
|
255
|
-
- Uses
|
|
256
|
-
- Uses BGRA input, a brightness gate, face-size/frame-margin/pose/landmark checks, and
|
|
245
|
+
- Uses `AVCaptureVideoDataOutput`, Apple Vision face/landmark detection, and the bundled dual-model NCNN detector
|
|
246
|
+
- Uses CPU inference; GPU/Vulkan inference is disabled
|
|
247
|
+
- Uses BGRA input, a brightness gate, face-size/frame-margin/pose/landmark checks, and two expanded face-bounds crops resized to the model input dimensions
|
|
257
248
|
- Automatically adjusts video mirroring and uses Vision Camera's selected analysis resolution
|
|
249
|
+
- NCNN inference is available on physical arm64 iOS devices. The included NCNN and OpenMP frameworks have no simulator slice, so simulator builds cannot run the camera liveness inference.
|
|
258
250
|
|
|
259
251
|
## Troubleshooting
|
|
260
252
|
|
|
261
|
-
###
|
|
253
|
+
### Legacy `FaceAntiSpoof` module not available
|
|
262
254
|
|
|
263
255
|
```ts
|
|
264
256
|
if (!isFaceAntiSpoofAvailable()) {
|
|
265
|
-
console.warn('
|
|
257
|
+
console.warn('The optional legacy FaceAntiSpoof module is unavailable.');
|
|
266
258
|
}
|
|
267
259
|
```
|
|
268
260
|
|
|
261
|
+
This check applies only to the legacy iOS NativeModule API. The Vision Camera output uses Nitro and does not require this module.
|
|
262
|
+
|
|
269
263
|
### iOS issues
|
|
270
264
|
|
|
271
265
|
- Ensure `NSCameraUsageDescription` exists in the app's Info.plist
|
|
@@ -276,15 +270,17 @@ if (!isFaceAntiSpoofAvailable()) {
|
|
|
276
270
|
|
|
277
271
|
- Confirm the app has camera permissions
|
|
278
272
|
- Ensure the module is properly linked in the app project
|
|
279
|
-
-
|
|
273
|
+
- The NCNN liveness engine is bundled for `arm64-v8a` and `armeabi-v7a`
|
|
274
|
+
- Check native logs for model-loading errors
|
|
280
275
|
|
|
281
276
|
## Platform support
|
|
282
277
|
|
|
283
|
-
| Platform |
|
|
284
|
-
|
|
285
|
-
| Android | ✅
|
|
286
|
-
| iOS
|
|
287
|
-
|
|
|
278
|
+
| Platform | Camera-output inference | GPU acceleration | Notes |
|
|
279
|
+
|----------|-------------------------|-------------------|-------|
|
|
280
|
+
| Android | ✅ Supported | ❌ No | Dual-model NCNN CPU inference on `arm64-v8a` and `armeabi-v7a` |
|
|
281
|
+
| iOS physical arm64 device | ✅ Supported | ❌ No | Dual-model NCNN CPU inference |
|
|
282
|
+
| iOS simulator | ❌ Not supported | ❌ No | The bundled NCNN and OpenMP frameworks have no simulator slice |
|
|
283
|
+
| Web | ❌ Not supported | ❌ No | Native camera processing only |
|
|
288
284
|
|
|
289
285
|
## License
|
|
290
286
|
|
|
@@ -14,7 +14,14 @@ Pod::Spec.new do |s|
|
|
|
14
14
|
s.swift_version = '5.0'
|
|
15
15
|
s.pod_target_xcconfig = {
|
|
16
16
|
'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64',
|
|
17
|
-
'HEADER_SEARCH_PATHS' => '$(inherited) ${PODS_TARGET_SRCROOT}/nitrogen/generated/shared/c++ ${PODS_TARGET_SRCROOT}/nitrogen/generated/ios ${PODS_TARGET_SRCROOT}/nitrogen/generated/ios/c++'
|
|
17
|
+
'HEADER_SEARCH_PATHS' => '$(inherited) ${PODS_TARGET_SRCROOT}/nitrogen/generated/shared/c++ ${PODS_TARGET_SRCROOT}/nitrogen/generated/ios ${PODS_TARGET_SRCROOT}/nitrogen/generated/ios/c++',
|
|
18
|
+
'HEADER_SEARCH_PATHS[sdk=iphoneos*]' => '$(inherited) "${PODS_TARGET_SRCROOT}/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers"',
|
|
19
|
+
'GCC_PREPROCESSOR_DEFINITIONS[sdk=iphoneos*]' => '$(inherited) HAS_NCNN=1',
|
|
20
|
+
'GCC_PREPROCESSOR_DEFINITIONS[sdk=iphonesimulator*]' => '$(inherited) HAS_NCNN=0',
|
|
21
|
+
'FRAMEWORK_SEARCH_PATHS[sdk=iphoneos*]' => '$(inherited) "${PODS_TARGET_SRCROOT}/ios/ncnn.xcframework/ios-arm64" "${PODS_TARGET_SRCROOT}/ios/openmp.xcframework/ios-arm64"',
|
|
22
|
+
'OTHER_LDFLAGS[sdk=iphoneos*]' => '$(inherited) -framework ncnn -framework openmp -lc++',
|
|
23
|
+
'CLANG_CXX_LANGUAGE_STANDARD' => 'c++17',
|
|
24
|
+
'CLANG_CXX_LIBRARY' => 'libc++'
|
|
18
25
|
}
|
|
19
26
|
|
|
20
27
|
load 'nitrogen/generated/ios/VisionCameraSpoofDetector+autolinking.rb'
|
|
@@ -26,7 +33,10 @@ Pod::Spec.new do |s|
|
|
|
26
33
|
'nitrogen/generated/ios/**/*.{cpp,mm,swift}',
|
|
27
34
|
'nitrogen/generated/ios/VisionCameraSpoofDetector-Swift-Cxx-Bridge.hpp',
|
|
28
35
|
]
|
|
29
|
-
s.public_header_files =
|
|
36
|
+
s.public_header_files = [
|
|
37
|
+
'ios/NcnnLivenessDetector.h',
|
|
38
|
+
'nitrogen/generated/ios/VisionCameraSpoofDetector-Swift-Cxx-Bridge.hpp',
|
|
39
|
+
]
|
|
30
40
|
s.private_header_files = [
|
|
31
41
|
'nitrogen/generated/shared/**/*.hpp',
|
|
32
42
|
'nitrogen/generated/ios/c++/**/*.{h,hpp}',
|
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()
|