face_camera
A Flutter camera plugin that detects face in real-time.
Preview
Installation
First, add face_camera
as a dependency in your pubspec.yaml file.
face_camera: ^0.0.3
iOS
- Minimum iOS Deployment Target: 10.0
- Follow this link and setup
ML Kit
this is required forface_camera
to function properly iniOS
Add two rows to the ios/Runner/Info.plist:
- one with the key
Privacy - Camera Usage Description
and a usage description. - and one with the
key Privacy - Microphone Usage Description
and a usage description.
If editing Info.plist
as text, add:
<key>NSCameraUsageDescription</key>
<string>your usage description here</string>
<key>NSMicrophoneUsageDescription</key>
<string>your usage description here</string>
Android
- Change the minimum Android sdk version to 21 (or higher) in your
android/app/build.gradle
file.
minSdkVersion 21
Usage
- The first step is to initialize
face_camera
inmain.dart
void main() async{
WidgetsFlutterBinding.ensureInitialized(); //Add this
await FaceCamera.intialize(); //Add this
runApp(const MyApp());
}
- Then render the component in your application setting the onCapture callback.
@override
Widget build(BuildContext context) {
return Scaffold(
body: SmartFaceCamera(
autoCapture: true,
defaultCameraLens: CameraLens.front,
message: 'Center your face in the square',
onCapture: (File? image){
},
)
);
}
Customization
Here is a list of properties available to customize your widget:
Name | Type | Description |
---|---|---|
onCapture | Function(File) | callback invoked when camera captured image |
imageResolution | ImageResolution | used this to set image resolution |
defaultCameraLens | CameraLens | used this to set initial camera lens direction |
defaultFlashMode | CameraFlashMode | used this to set initial flash mode |
enableAudio | bool | set false to disable caputre sound |
autoCapture | bool | set true to capture image on face detected |
showControls | bool | set false to hide all controls |
showCaptureControl | bool | set false to hide capture control icon |
showFlashControl | bool | set false to hide flash control control icon |
showCameraLensControl | bool | set false to hide camera lens control icon |
message | String | use this pass a message above the camera |
messageStyle | TextStyle | style applied to the message widget |
orientation | CameraOrientation | use this to lock camera orientation |
captureControlIcon | Widget | use this to render a custom widget for capture control |
lensControlIcon | Widget | use this to render a custom widget for camera lens control |
flashControlBuilder | FlashControlBuilder | use this to build a custom widget for flash control based on camera flash mode |
Contributions
Contributions of any kind are more than welcome! Feel free to fork and improve face_camera
in any way you want, make a pull request, or open an issue.
Support the Library
You can support the library by liking it on pub, staring in on Github and reporting any bugs you encounter.