5.1.0 • Published 9 months ago

@projectleannation/face-detection v5.1.0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
9 months ago

@projectleannation/face-detection

Unofficial Capacitor plugin for ML Kit Face Detection.^1

Installation

npm install @projectleannation/face-detection
npx cap sync

Android

You need to add the following meta data in the application tag in your AndroidManifest.xml:

<meta-data android:name="com.google.mlkit.vision.DEPENDENCIES" android:value="face"/>
<!-- To use multiple models: android:value="face,model2,model3" -->

Variables

This plugin will use the following project variables (defined in your app’s variables.gradle file):

  • $mlkitFaceDetectionVersion version of com.google.mlkit:face-detection (default: 16.1.5)
  • $playServicesMlkitFaceDetectionVersion version of com.google.android.gms:play-services-mlkit-face-detection (default: 17.1.0)

Configuration

No configuration required for this plugin.

Demo

A working example can be found here: robingenz/capacitor-mlkit-plugin-demo

Usage

import {
  FaceDetection,
  PerformanceMode,
  LandmarkMode,
  ContourMode,
  ClassificationMode,
} from '@projectleannation/face-detection';

const processImage = async () => {
  await FaceDetection.processImage({
    path: 'path/to/image.jpg',
    performanceMode: PerformanceMode.Fast,
    landmarkMode: LandmarkMode.All,
    contourMode: ContourMode.All,
    classificationMode: ClassificationMode.All,
    minFaceSize: 0.1,
    enableTracking: false,
  });
};

API

processImage(...)

processImage(options: ProcessImageOptions) => Promise<ProcessImageResult>

Detects human faces from the supplied image.

Only available on Android and iOS.

ParamType
optionsProcessImageOptions

Returns: Promise<ProcessImageResult>

Since: 5.1.0


Interfaces

ProcessImageResult

PropTypeDescriptionSince
facesFace[]The detected faces.5.1.0

Face

Represents a face detected by FaceDetector.

PropTypeDescriptionSince
boundsRectReturns the axis-aligned bounding rectangle of the detected face.5.1.0
landmarksFaceLandmark[]Returns a list of face landmarks.5.1.0
contoursFaceContour[]Returns a list of face contours.5.1.0
trackingIdnumberReturns the tracking ID if the tracking is enabled.5.1.0
headEulerAngleXnumberReturns the rotation of the face about the horizontal axis of the image. Positive euler X is the face is looking up.5.1.0
headEulerAngleYnumberReturns the rotation of the face about the vertical axis of the image. Positive euler y is when the face turns toward the right side of the image that is being processed.5.1.0
headEulerAngleZnumberReturns the rotation of the face about the axis pointing out of the image. Positive euler z is a counter-clockwise rotation within the image plane.5.1.0
smilingProbabilitynumberReturns a value between 0.0 and 1.0 giving a probability that the face is smiling.5.1.0
leftEyeOpenProbabilitynumberReturns a value between 0.0 and 1.0 giving a probability that the face's left eye is open.5.1.0
rightEyeOpenProbabilitynumberReturns a value between 0.0 and 1.0 giving a probability that the face's right eye is open.5.1.0

Rect

Rect holds four integer coordinates for a rectangle.

PropTypeDescriptionSince
leftnumberThe X coordinate of the left side of the rectangle5.1.0
topnumberThe Y coordinate of the top of the rectangle5.1.0
rightnumberThe X coordinate of the right side of the rectangle5.1.0
bottomnumberThe Y coordinate of the bottom of the rectangle5.1.0

FaceLandmark

Represent a face landmark. A landmark is a point on a detected face, such as an eye, nose, or mouth.

PropTypeDescriptionSince
typeLandmarkTypeGets the FaceLandmark.LandmarkType type.5.1.0
positionPointGets a 2D point for landmark position, where (0, 0) is the upper-left corner of the image.5.1.0

Point

Point holds two coordinates

PropType
xnumber
ynumber

FaceContour

Represent a face contour. A contour is a list of points on a detected face, such as the mouth.

PropTypeDescriptionSince
typeContourTypeGets the FaceContour.ContourType type.5.1.0
pointsPoint[]Gets a list of 2D points for this face contour, where (0, 0) is the upper-left corner of the image.5.1.0

ProcessImageOptions

PropTypeDescriptionDefaultSince
pathstringThe local path to the image file.5.1.0
performanceModePerformanceModeDefines options to control accuracy / speed trade-offs in performing face detection.PerformanceMode.Fast5.1.0
landmarkModeLandmarkModeDefines options to enable face landmarks or not.LandmarkMode.None5.1.0
contourModeContourModeDefines options to enable face contours or not.ContourMode.None5.1.0
classificationModeClassificationModeDefines options for characterizing attributes such as "smiling" * and "eyes open".ClassificationMode.None5.1.0
minFaceSizenumberSets the smallest desired face size, expressed as a proportion of the width of the head to the image width.0.15.1.0
enableTrackingbooleanEnables face tracking, which will maintain a consistent ID for each face when processing consecutive frames. Tracking should be disabled for handling a series of non-consecutive still images.false5.1.0

Enums

LandmarkType

MembersValueDescriptionSince
MouthBottom0The center of the subject's bottom lip.5.1.0
LeftCheek1The midpoint between the subject's left mouth corner and the outer corner of the subject's left eye. For full profile faces, this becomes the centroid of the nose base, nose tip, left ear lobe and left ear tip.5.1.0
LeftEar3The midpoint of the subject's left ear tip and left ear lobe.5.1.0
LeftEye4The center of the subject's left eye cavity.5.1.0
MouthLeft5The subject's left mouth corner where the lips meet.5.1.0
NoseBase6The midpoint between the subject's nostrils where the nose meets the face.5.1.0
RightCheek7The midpoint between the subject's right mouth corner and the outer corner of the subject's right eye. For full profile faces, this becomes the centroid of the nose base, nose tip, right ear lobe and right ear tip.5.1.0
RightEar9The midpoint of the subject's right ear tip and right ear lobe.5.1.0
RightEye10The center of the subject's right eye cavity.5.1.0
MouthRight11The subject's right mouth corner where the lips meet.5.1.0

ContourType

MembersValueDescriptionSince
Face1The outline of the subject's face.5.1.0
LeftEyebrowTop2The top outline of the subject's left eyebrow.5.1.0
LeftEyebrowBottom3The bottom outline of the subject's left eyebrow.5.1.0
RightEyebrowTop4The top outline of the subject's right eyebrow.5.1.0
RightEyebrowBottom5The bottom outline of the subject's right eyebrow.5.1.0
LeftEye6The outline of the subject's left eye cavity.5.1.0
RightEye7The outline of the subject's right eye cavity.5.1.0
UpperLipTop8The top outline of the subject's upper lip.5.1.0
UpperLipBottom9The bottom outline of the subject's upper lip.5.1.0
LowerLipTop10The top outline of the subject's lower lip.5.1.0
LowerLipBottom11The bottom outline of the subject's lower lip.5.1.0
NoseBridge12The outline of the subject's nose bridge.5.1.0
NoseBottom13The outline of the subject's nose bridge.5.1.0
LeftCheek14The center of the left cheek.5.1.0
RightCheek15The center of the right cheek.5.1.0

PerformanceMode

MembersValueDescriptionSince
Fast1Indicates a preference for speed in the options that may make an accuracy vs. speed trade-off. This will tend to detect fewer faces and may be less precise in determining values such as position, but will run faster.5.1.0
Accurate2Indicates a preference for accuracy in the options that may make an accuracy vs. speed trade-off. This will tend to detect more faces and may be more precise in determining values such as position, at the cost of speed.5.1.0

LandmarkMode

MembersValueDescriptionSince
None1Does not perform landmark detection.5.1.0
All2Detects FaceLandmark for a given face.5.1.0

ContourMode

MembersValueDescriptionSince
None1Does not perform contour detection.5.1.0
All2Detects FaceContour for a given face. Note that it would return contours for up to 5 faces5.1.0

ClassificationMode

MembersValueDescriptionSince
None1Does not perform classification.5.1.0
All2Performs "eyes open" and "smiling" classification.5.1.0

Terms & Privacy

This plugin uses the Google ML Kit:

Changelog

See CHANGELOG.md.

License

See LICENSE.

^1: This project is not affiliated with, endorsed by, sponsored by, or approved by Google LLC or any of their affiliates or subsidiaries.

5.1.0

9 months ago