react-native-vision-camera-spoof-detector
v1.0.12
Published
High-performance face anti-spoofing and liveness detection module for React Native Vision Camera. Uses TensorFlow Lite with GPU acceleration and optimized YUV processing.
Maintainers
Readme
React Native Vision Camera Face Anti-Spoofing Detector
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.
Features
✅ Real-time Face Liveness Detection - Distinguish between live faces and spoofed images/videos
✅ GPU Acceleration - TensorFlow Lite GPU delegate support
✅ NNAPI Support - Hardware acceleration fallback for older devices
✅ Multi-Threading - Non-blocking background processing
✅ Optimized YUV Processing - Direct frame processing without Bitmap conversion
✅ TypeScript Support - Full type definitions included
✅ Lightweight - Only 20.92 MB (optimized build)
✅ Production Ready - Tested and stable
Installation
npm install react-native-vision-camera-spoof-detector
# or
yarn add react-native-vision-camera-spoof-detectorPeer Dependencies
This module requires the following peer dependencies:
npm install react-native-vision-camera react-native-reanimated react-native-worklets-coreQuick Start
1. Initialize the Module
import { initializeFaceAntiSpoof } from 'react-native-vision-camera-spoof-detector';
// In your app initialization
useEffect(() => {
initializeFaceAntiSpoof()
.then(() => console.log('Face anti-spoof initialized'))
.catch(err => console.error('Init failed:', err));
}, []);2. Use in Frame Processor
import { useFrameProcessor } from 'react-native-vision-camera';
import { faceAntiSpoofFrameProcessor } from 'react-native-vision-camera-spoof-detector';
export function CameraScreen() {
const frameProcessor = useFrameProcessor((frame) => {
'worklet';
const result = runAsync(frame, () => {
'worklet';
return faceAntiSpoofFrameProcessor(frame);
});
// Use the result
if (result?.isLive) {
console.log('Live face detected:', result.label);
}
}, []);
return (
<Camera
device={device}
frameProcessor={frameProcessor}
// ... other props
/>
);
}API Reference
initializeFaceAntiSpoof(): Promise<boolean>
Initializes the face anti-spoofing module. Must be called before using the frame processor.
Returns: Promise<boolean> - true if initialization was successful
const isInitialized = await initializeFaceAntiSpoof();faceAntiSpoofFrameProcessor(frame): FaceAntiSpoofingResult | null
Process a camera frame for face anti-spoofing detection.
Parameters:
frame(Frame) - Vision Camera frame object
Returns:
{
isLive: boolean; // true if face is live
label: string; // "Live Face" or "Spoof Face"
neuralNetworkScore: number; // 0.0-1.0 (lower = more likely live)
laplacianScore: number; // Image quality metric
combinedScore: number; // 0.0-1.0 weighted score
error?: string; // Error message if any
}isFaceAntiSpoofAvailable(): boolean
Check if the native module is available.
const available = isFaceAntiSpoofAvailable();Performance
Optimization Techniques
- Multi-Threading: Heavy processing runs on a dedicated background thread, keeping camera smooth
- GPU Acceleration: Uses TensorFlow Lite GPU delegate when available
- NNAPI Support: Falls back to NNAPI for hardware acceleration on older devices
- YUV Direct Processing: No Bitmap conversion - works directly with camera frame data
- Reusable Buffers: Allocates buffers once, reuses for each frame
- Single-Frame Processing: Only processes one frame at a time to prevent queue overflow
Benchmark
| Metric | Value | |--------|-------| | Processing Time | ~50-100ms per frame | | Memory Usage | <30 MB (runtime) | | Package Size | 20.92 MB | | Support | Android 21+ |
Architecture
VisionCamera (30fps callback)
↓
faceAntiSpoofFrameProcessor()
↓
Submit to background executor
↓
Non-blocking return
↓
Latest result availableProcessing happens on:
- Single-threaded
Executors.newSingleThreadExecutor() - Daemon thread for proper lifecycle
- Non-blocking callback returns immediately
Configuration
Accelerator Types
The module automatically selects the best available accelerator:
- GPU - TensorFlow Lite GPU delegate (fastest)
- NNAPI - Android Neural Networks API
- CPU - Fallback for older devices
Check which accelerator is in use:
import FaceAntiSpoof from 'react-native-vision-camera-spoof-detector';
FaceAntiSpoof.checkModelStatus()
.then(status => console.log('Accelerator:', status.accelerator));Troubleshooting
Module Not Available
if (!isFaceAntiSpoofAvailable()) {
console.error('Face anti-spoof not available on this device');
}Initialization Fails
try {
await initializeFaceAntiSpoof();
} catch (error) {
console.error('Init error:', error.message);
}Frame Processing Too Slow
- Ensure you're using a physical device (emulators are slow)
- Check if GPU acceleration is working
- Reduce frame processor workload
- Consider skipping some frames
License
MIT © JESCON TECHNOLOGIES PVT LTD
Support
For issues and feature requests, visit: GitHub Issues
Changelog
See CHANGELOG.md for version history and updates.
Package Version: 1.0.0
Last Updated: November 18, 2025
