smart_selfie_capture 0.0.1+2
smart_selfie_capture: ^0.0.1+2 copied to clipboard
A Flutter package for capturing selfies with face validation, object detection, and liveness checks. Includes customizable messages and real-time feedback.
Smart Selfie Capture #
A comprehensive Flutter package for capturing selfies with advanced features including face validation, liveness checks, and real-time feedback. Perfect for KYC, identity verification, and secure photo capture applications.
โจ Features #
- ๐ฏ Real-time Face Detection - Powered by Google ML Kit
- ๐ Three Liveness Check Modes - Blink, mouth open, or both
- ๐ Advanced Face Validation - Size, orientation, eyes, and smile detection
- ๐จ Fully Customizable UI - Colors, messages, instructions, and themes
- โก Instant Visual Feedback - Face overlay with corner brackets
- ๐ Cross-platform - iOS 15.5+ and Android 21+
- ๐งช Well Tested - 26 unit tests with comprehensive coverage
- ๐ Complete Documentation - API reference and examples included
๐ธ Screenshots #
| Basic Selfie | Liveness Check | Smile Detection |
|---|---|---|
| Face detection with overlay | Blink or mouth open | Smile validation |
๐ Quick Start #
Installation #
Add to your pubspec.yaml:
dependencies:
smart_selfie_capture: ^0.0.1
Then run:
flutter pub get
Platform-Specific Setup #
๐ฑ iOS Setup
- Add camera permission to
ios/Runner/Info.plist:
<key>NSCameraUsageDescription</key>
<string>Camera access is required to capture your selfie</string>
- Set minimum iOS version in
ios/Podfile:
platform :ios, '15.5'
- Run pod install:
cd ios && pod install
๐ค Android Setup
- Update minimum SDK in
android/app/build.gradle:
android {
defaultConfig {
minSdkVersion 21
compileSdkVersion 34
}
}
- Add permissions to
android/app/src/main/AndroidManifest.xml:
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" android:required="true" />
- Handle camera permissions in your app before opening the capture screen.
๐ก Usage Examples #
Basic Selfie Capture #
Simple selfie capture with default settings:
import 'package:smart_selfie_capture/smart_selfie_capture.dart';
SelfieCaptureScreen(
config: const SelfieConfig(
title: 'Take a Selfie',
enableLivenessCheck: false,
),
onCaptureComplete: (SelfieResult result) {
print('Image saved: ${result.imagePath}');
print('Validated: ${result.isValidated}');
Navigator.pop(context);
},
)
Identity Verification with Liveness #
Complete verification with mouth opening detection:
SelfieCaptureScreen(
config: const SelfieConfig(
title: 'Verify Your Identity',
subtitle: 'Position your face in the frame',
enableLivenessCheck: true,
livenessCheckType: LivenessCheckType.mouthOpen,
livenessBlinkCount: 1,
customMessage: 'Please ensure you are in a well-lit area',
instructions: [
'Look directly at the camera',
'Open your mouth when prompted',
'Hold still during capture',
],
validationRules: ValidationRules(
requireFrontalFace: true,
requireEyesOpen: true,
minFaceSize: 0.4,
maxFaceSize: 0.7,
),
primaryColor: Colors.blue,
),
onCaptureComplete: (result) {
if (result.isValidated && result.livenessCheckPassed) {
// Process verified selfie
uploadToServer(result.imagePath);
}
},
onCancel: () {
Navigator.pop(context);
},
)
Smile Detection #
Capture a selfie with smile requirement:
SelfieCaptureScreen(
config: SelfieConfig(
title: 'Smile Please! ๐',
subtitle: 'Show us your best smile',
validationRules: const ValidationRules(
requireSmile: true,
requireEyesOpen: true,
minFaceSize: 0.35,
),
enableLivenessCheck: false,
primaryColor: Colors.orange,
),
onCaptureComplete: (result) {
showDialog(
context: context,
builder: (_) => AlertDialog(
title: Text('Perfect!'),
content: Image.file(File(result.imagePath)),
),
);
},
)
๐ฏ Liveness Check Types #
The package supports three liveness detection modes:
| Type | Description | Use Case |
|---|---|---|
LivenessCheckType.blink |
Detects eye blinks | Traditional liveness check |
LivenessCheckType.mouthOpen |
Detects mouth opening | Alternative liveness method |
LivenessCheckType.both |
Requires both actions | Maximum security |
Example:
SelfieConfig(
enableLivenessCheck: true,
livenessCheckType: LivenessCheckType.mouthOpen,
livenessBlinkCount: 1, // Number of times to perform action
)
โ๏ธ Configuration Options #
SelfieConfig #
| Property | Type | Default | Description |
|---|---|---|---|
title |
String | 'Capture Selfie' | Screen title |
subtitle |
String | 'Position your face...' | Subtitle text |
instructions |
List<String> | [...] | List of instructions |
validationRules |
ValidationRules | ValidationRules() | Face validation criteria |
enableLivenessCheck |
bool | true | Enable liveness detection |
livenessCheckType |
LivenessCheckType | mouthOpen | Type of liveness check |
livenessBlinkCount |
int | 2 | Required action count |
enableObjectDetection |
bool | true | Enable object detection |
primaryColor |
Color | Colors.blue | Primary UI color |
backgroundColor |
Color | Colors.black | Background color |
captureDelay |
Duration | 3 seconds | Countdown duration |
customMessage |
String? | null | Custom banner message |
ValidationRules #
Fine-tune face validation behavior:
| Property | Type | Default | Description |
|---|---|---|---|
requireFrontalFace |
bool | true | Face must look at camera |
requireEyesOpen |
bool | true | Eyes must be open |
requireSmile |
bool | false | Smile detection |
minFaceSize |
double | 0.3 | Min face size (0.0-1.0) |
maxFaceSize |
double | 0.8 | Max face size (0.0-1.0) |
minEulerAngleX/Y/Z |
double | -15.0 | Head angle tolerance |
maxEulerAngleX/Y/Z |
double | 15.0 | Head angle tolerance |
allowMultipleFaces |
bool | false | Allow multiple faces |
Example:
ValidationRules(
requireFrontalFace: true,
requireEyesOpen: true,
minFaceSize: 0.4, // Face should be 40%+ of frame
maxFaceSize: 0.7, // Face should be max 70% of frame
minEulerAngleY: -15.0, // Allow 15ยฐ left/right turn
maxEulerAngleY: 15.0,
)
SelfieResult #
The capture result contains:
| Property | Type | Description |
|---|---|---|
imagePath |
String | Absolute path to saved image |
isValidated |
bool | Face validation status |
livenessCheckPassed |
bool | Liveness check status |
validationDetails |
Map | Detailed validation data |
capturedAt |
DateTime | Capture timestamp |
Example:
onCaptureComplete: (SelfieResult result) {
print('Image: ${result.imagePath}');
print('Valid: ${result.isValidated}');
print('Live: ${result.livenessCheckPassed}');
print('Blinks: ${result.validationDetails['blinkCount']}');
print('Time: ${result.capturedAt}');
}
๐ Documentation #
- API Reference - Complete API documentation
- Contributing Guide - How to contribute
- Changelog - Version history
- Example App - Working examples
๐ง Troubleshooting #
Camera not initializing
- Verify camera permissions are granted
- Check platform-specific setup is complete
- Ensure device has a working camera
- Test on physical device (emulators may have issues)
Face not detected
- Improve lighting conditions
- Position face in center of frame
- Remove obstructions (glasses, masks, hats)
- Ensure face is within size range (30-80% of frame)
- Check that face is looking at camera
Liveness check not working
- Ensure good lighting for eye/mouth detection
- Try different liveness types (blink vs mouth open)
- Increase
livenessBlinkCountthreshold - Check that eyes/mouth are clearly visible
Performance issues
- Use
ResolutionPreset.mediumfor older devices - Disable
enableObjectDetectionif not needed - Reduce validation strictness
- Test on physical device (emulators are slower)
ML Kit errors
- Verify Google Play Services (Android)
- Check minimum platform requirements
- Ensure internet connection for first-time ML Kit download
- Clear app cache and reinstall
๐ฏ Use Cases #
- ๐ค KYC Verification - Know Your Customer identity checks
- ๐ฆ Banking Apps - Secure customer onboarding
- ๐ซ Event Check-in - Photo-based attendance
- ๐ ID Verification - Government ID matching
- ๐จโโ๏ธ Healthcare - Patient identification
- ๐ Ride Sharing - Driver verification
- ๐ข Access Control - Building entry systems
โก Performance Tips #
- Resolution: Use
mediumfor faster processing on older devices - Validation: Relax angle tolerances for easier capture
- Liveness: Single action is faster than multiple
- Object Detection: Disable if not needed for security
๐ Requirements #
| Requirement | Minimum Version |
|---|---|
| Flutter SDK | 3.3.0+ |
| Dart SDK | 3.9.2+ |
| iOS | 15.5+ |
| Android | API 21+ (5.0) |
๐ How It Works #
Process Flow #
- ๐ฌ Initialization - Camera and ML Kit face detectors start
- ๐๏ธ Face Detection - Real-time detection on camera stream (30 FPS)
- โ
Validation - Face checked against configured rules:
- Face size 30-80% of frame (distance check)
- Head pose within ยฑ15ยฐ (frontal face)
- Eyes open detection
- Optional smile detection
- ๐ด Liveness Check - Blink or mouth open to prevent photo spoofing
- โฑ๏ธ Countdown - 3-second countdown with visual feedback
- ๐ธ Capture - High-resolution image captured and saved
- ๐ฆ Result - Returns SelfieResult with validation data
Visual Feedback Features #
- โจ Real-time face overlay with corner brackets
- ๐จ Color-coded status messages (green = good, red = error)
- โฐ Countdown timer animation
- ๐ Scanning animation during detection
๐ License #
This project is licensed under the MIT License - see the LICENSE file for details.
๐ค Contributing #
Contributions are welcome! Please read CONTRIBUTING.md for guidelines on:
- Code standards and style
- Testing requirements
- Pull request process
- Issue reporting
๐ Changelog #
See CHANGELOG.md for version history and release notes.
๐ Issues & Support #
- Bug Reports: Open an issue
- Feature Requests: Request a feature
- Questions: Ask a question
๐ Acknowledgments #
This package is built on top of excellent open-source projects:
- Google ML Kit - Face detection and classification
- Camera Plugin - Flutter camera integration
- Flutter Community - For continuous support and feedback
โญ Show Your Support #
If this package helped your project, please:
Made with โค๏ธ for the Flutter community