Skip to content

Latest commit

 

History

History
79 lines (55 loc) · 3.14 KB

README.md

File metadata and controls

79 lines (55 loc) · 3.14 KB

Google's ML Kit Face Detection for Flutter

Pub Version analysis Star on Github License: MIT

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 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;
  }
}

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.