google_mlkit_face_detection 0.0.1 google_mlkit_face_detection: ^0.0.1 copied to clipboard
A Flutter plugin to use Google's ML Kit Face Detection to detect faces in an image, identify key facial features, and get the contours of detected faces.
Google's ML Kit Face Detection for Flutter #
A Flutter plugin to use Google's ML Kit Face Detection to detect faces in an image, identify key facial features, and get the contours of detected faces.
Getting Started #
Before you get started read about the requirements and known issues of this plugin here.
Usage #
Face Detection #
Create an instance of InputImage
Create an instance of InputImage
as explained here.
final InputImage inputImage;
Create an instance of FaceDetector
final options = FaceDetectorOptions();
final faceDetector = FaceDetector(options: options);
Process image
final List<Face> faces = await faceDetector.processImage(inputImage);
for (Face face in faces) {
final Rect boundingBox = face.boundingBox;
final double rotY = face.headEulerAngleY; // Head is rotated to the right rotY degrees
final double rotZ = face.headEulerAngleZ; // Head is tilted sideways rotZ degrees
// If landmark detection was enabled with FaceDetectorOptions (mouth, ears,
// eyes, cheeks, and nose available):
final FaceLandmark leftEar = face.getLandmark(FaceLandmarkType.leftEar);
if (leftEar != null) {
final Point<double> leftEarPos = leftEar.position;
}
// If classification was enabled with FaceDetectorOptions:
if (face.smilingProbability != null) {
final double smileProb = face.smilingProbability;
}
// If face tracking was enabled with FaceDetectorOptions:
if (face.trackingId != null) {
final int id = face.trackingId;
}
}
Release resources with close()
faceDetector.close();
Example app #
Find the example app here.
Contributing #
Contributions are welcome. In case of any problems look at existing issues, if you cannot find anything related to your problem then open an issue. Create an issue before opening a pull request for non trivial fixes. In case of trivial fixes open a pull request directly.