Skip to content

Repository files navigation

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: ^<latest-version>

iOS


  • Minimum iOS Deployment Target: 15.5.0
  • Follow this link and setup ML Kit this is required for face_camera to function properly on iOS

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 in main.dart
voidmain() async{
WidgetsFlutterBinding.ensureInitialized(); //Add thisawaitFaceCamera.initialize(); //Add thisrunApp(constMyApp());
}
  • Create a new FaceCameraController controller, setting the onCapture callback.
lateFaceCameraController controller;
@overridevoidinitState() {
controller =FaceCameraController(
autoCapture:true,
defaultCameraLens:CameraLens.front,
onCapture: (File? image) {
},
);
super.initState();
}
  • Then render the component in your application using the required options.
@overrideWidgetbuild(BuildContext context) {
returnScaffold(
body:SmartFaceCamera(
controller: controller,
message:'Center your face in the square',
)
);
}

Customization


Here is a list of properties available to customize your widget:

NameTypeDescription
controllerFaceCameraControllerThe controller for the [SmartFaceCamera] widget
showControlsboolset false to hide all controls
showCaptureControlboolset false to hide capture control icon
showFlashControlboolset false to hide flash control control icon
showCameraLensControlboolset false to hide camera lens control icon
messageStringuse this pass a message above the camera
messageStyleTextStylestyle applied to the message widget
lensControlIconWidgetuse this to render a custom widget for camera lens control
flashControlBuilderFlashControlBuilderuse this to build custom widgets for flash control based on camera flash mode
messageBuilderMessageBuilderuse this to build custom messages based on face position
indicatorShapeIndicatorShapeuse this to change the shape of the face indicator
indicatorAssetImageStringuse this to pass an asset image when IndicatorShape is set to image
indicatorBuilderIndicatorBuilderuse this to build custom widgets for the face indicator
captureControlBuilderCaptureControlBuilderuse this to build custom widgets for capture control
autoDisableCaptureControlboolset true to disable capture control widget when no face is detected



Here is a list of properties available to customize your widget from the controller:

NameTypeDescription
onCaptureFunction(File?)callback invoked when camera captures image
onFaceDetectedFunction(DetectedFace?)callback invoked when camera detects face
imageResolutionImageResolutionuse this to set image resolution
defaultCameraLensCameraLensuse this to set initial camera lens direction
defaultFlashModeCameraFlashModeuse this to set initial flash mode
enableAudioboolset false to disable capture sound
autoCaptureboolset true to capture image on face detected
ignoreFacePositioningboolset true to trigger onCapture even when the face is not well positioned
orientationCameraOrientationuse this to lock camera orientation
performanceModeFaceDetectorModeUse this to set your preferred performance 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 donating, liking it on Pub, starring it on GitHub, and reporting any bugs you encounter.

💖 Show Love on Selar

About

A Flutter camera plugin that detects face in real-time

Resources

Stars

75 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages