flutter_liveness 1.0.0 copy "flutter_liveness: ^1.0.0" to clipboard
flutter_liveness: ^1.0.0 copied to clipboard

On-device face liveness detection for Flutter using a MobileNetV2 model. Detect spoof attacks from photos and videos, no internet required.

flutter_liveness #

Model: MobileNetV2 Dataset: Spoof/Real License: MIT

Lightweight on-device face liveness detection for Flutter, powered by MobileNetV2 from open liveness research.

✨ Features #

  • On-device liveness detection — no server required
  • Ships with pre-trained MobileNetV2 model
  • Uses TensorFlow Lite — optimized for real-time
  • Simple API — plug & play
  • Blur & clarity detector (Laplacian filter)

🧠 Model Information #

This package uses a pre-trained MobileNetV2 face liveness model trained as described in:

Using MobileNetV2 (Zawar, et al., 2023)

From the open-source project: biometric-technologies/liveness-detection-model

Model licensed under MIT, included with attribution.

Class meaning:

  • 0 = real
  • 1 = spoof

🚀 Usage #

Initialize #

import 'package:flutter_liveness/flutter_liveness.dart';
import 'package:image/image.dart' as imglib;

late final FlutterLiveness liveness;

Future<void> initLiveness() async {
  liveness = await FlutterLiveness.create();
}

Analyze a face image #

Future<void> check(Uint8List faceBytes) async {
  final img = imglib.decodeImage(faceBytes);
  if (img == null) throw Exception("Invalid image");

  final result = await liveness.analyze(img);

  print("Live: ${result.isLive}");
  print("Score (P(spoof)): ${result.score}");
  print("Laplacian: ${result.laplacian}");
  print("Inference time: ${result.time.inMilliseconds} ms");
}

Cleanup #

@override
void dispose() {
  liveness.dispose();
  super.dispose();
}

📊 Output Example #

Live: true
Score (P(spoof)): 0.023
Clarity (laplacian): 1812
Inference time: 29 ms

⚙️ Settings #

You can tune thresholds:

final liveness = await FlutterLiveness.create(
  options: LivenessOptions(
    threshold: 0.5, // sigmoid cutoff
    laplacianThreshold: 1000, // blur block
  ),
);

❗ Usage Notes #

  • Feed cropped face images (not full camera frames)
  • Calls are fast (~20–35ms on modern devices)
  • Throttle analysis: ~3–5 FPS recommended
  • Do not consider this as the only security mechanism for KYC/financial apps — use it as one signal in a trust pipeline

📱 Integration Tips #

  • Use camera plugin to stream frames
  • Detect faces with MLKit or any detector
  • Crop → send to liveness.analyze()
  • Combine with:
    • Face presence
    • Eye blink / movement (optional future enhancement)
    • Anti-tampering / screen detection

🔐 Disclaimer #

This library provides liveness estimation, not identity verification. Use responsibly and evaluate for your use-case security requirements.

🤝 Acknowledgements #

  • TensorFlow Lite team
  • Biometric Technologies OÜ for the model & research
  • Flutter community
8
likes
160
points
0
downloads

Publisher

verified publisherknottx.dev

Weekly Downloads

On-device face liveness detection for Flutter using a MobileNetV2 model. Detect spoof attacks from photos and videos, no internet required.

Repository (GitHub)
View/report issues

Topics

#liveness #detection #face #tflite

Documentation

API reference

Funding

Consider supporting this project:

github.com

License

MIT (license)

Dependencies

flutter, image, tflite_flutter

More

Packages that depend on flutter_liveness