tensorflow_face_verification 0.1.2
tensorflow_face_verification: ^0.1.2 copied to clipboard
AI Powered Face Verification (Face Embedding & Comparison)
Flutter Face Verification (Face Embedding & Comparison) #
This package delivers TensorFlow-powered face matching by leveraging Google ML Kitβs Face Detection, wrapped in a lightweight Dart helper class. It supports determining whether two faces belong to the same person and provides a similarity score for flexible comparisons.
- π§ 128D Face Embedding Generation (FaceNet model)
- π ML Kit Face Detection with auto-cropping
- πΈ Compare faces and compute similarity score
π¨ The code assumes the use of a tflite model
facenet.tflite
.
βοΈ Works offline β all computation is done on-device.
β Fully asynchronous and customizable.
π§ͺ Features #
- Match faces between two images
- Detect and crop the face region from an image
- Measure similarity between faces
- Offline use β no internet required
π§ͺ Note #
This package is rely on tflite_flutter.
π¨ This package may not work in the iOS simulator. It's recommended that you test with a physical device.
π¨ When creating a release archive (IPA), the symbols are stripped by Xcode, so the command flutter build ipa
may throw a Failed to lookup symbol ... symbol not found
error. To work around this:
- In Xcode, go to Target Runner > Build Settings > Strip Style
- Change from All Symbols to Non-Global Symbols
π Getting Started #
1. Add Your Model #
Place your model in assets/models/facenet.tflite
.
flutter:
assets:
- assets/models/facenet.tflite
βοΈ Usage Example #
Initialize #
await FaceVerification.init(modelPath: 'assets/models/facenet.tflite');
Compare Two Face Images #
bool isSame = await FaceVerification.instance.verifySamePerson(
File('path/to/image1.jpg'),
File('path/to/image2.jpg'),
threshold: 0.6,
);
print("Same person? $isSame");
Get Similarity Score #
double score = await FaceVerification.instance.getFaceSimilarityFromFile(
File('path/to/image1.jpg'),
File('path/to/image2.jpg'),
);
print("Similarity: $score");
Image image1 = ....;
Image image2 = ....;
double score = await FaceVerification.instance.getFaceSimilarityFromImage(
image1,
image2,
);
print("Similarity: $score");
Additional customizations #
Image image1FaceRegion = await FaceVerification.instance.extractFaceRegion(
File('path/to/image1.jpg')
);
Image image2FaceRegion = await FaceVerification.instance.extractFaceRegion(
File('path/to/image1.jpg')
);
List<double> image1EmbeddingVector = await FaceVerification.instance.extractFaceEmbedding(
image1FaceRegion
);
List<double> image2EmbeddingVector = await FaceVerification.instance.extractFaceEmbedding(
image2FaceRegion
);
double score = await FaceVerification.instance.getSimilarityScore(
image1EmbeddingVector, image2EmbeddingVector
);
print("Similarity: $score");
print("Same person ${score > 0.6}");
π€ Contributing #
Feel free to fork, modify, and submit a PR.
Suggestions, bug reports, or new features are welcome.
π License #
MIT License