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.
Before you get started read about the requirements and known issues of this plugin here.
Create an instance of InputImage
as explained here.
final InputImage inputImage;
final options = FaceDetectorOptions();
final faceDetector = FaceDetector(options: options);
final List<Face> faces = await faceDetector.processImage(inputImage);
for (Face face in faces) {
final Rect boundingBox = face.boundingBox;
final double rotX = face.headEulerAngleX; // Head is tilted up and down rotX degrees
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.landmarks[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;
}
}
faceDetector.close();
Find the example app here.
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.