@capacitor-mlkit/face-detection

中文文档
8.2.2发布于 2026/10/31Apache-2.0TypeScriptESM + CJS零依赖构建来源已验证近 30 天下载 6309

Capacitor plugin for ML Kit Face Detection on Android and iOS.

原始使用文档
文档目录25 节
  1. Use Cases
  2. Compatibility
  3. Installation
  4. Android
  5. iOS
  6. Configuration
  7. Demo
  8. Usage
  9. Detect faces in an image
  10. API
  11. processImage(...)
  12. Interfaces
  13. Enums
  14. FAQ
  15. Which platforms are supported by this plugin?
  16. Does the plugin recognize who is in the picture?
  17. What is the difference between landmarks and contours?
  18. How can I detect whether a person is smiling or has their e…
  19. What is the difference between this plugin and the Face Mes…
  20. Can I use this plugin with Ionic, React, Vue or Angular?
  21. Related Plugins
  22. Terms & Privacy
  23. Newsletter
  24. Changelog
  25. License

Capacitor ML Kit Face Detection Plugin

Unofficial Capacitor plugin for ML Kit Face Detection.[^1]

Use Cases

The Face Detection plugin is typically used whenever an app needs to locate faces in an image, for example:

  • Photo organization: Detect which photos contain faces and where they are located, for example to crop thumbnails around them.
  • Selfie effects: Use the detected face landmarks and contours to position stickers or other virtual elements on faces.
  • Smile detection: Use the classification results to determine the probability that a person is smiling or has their eyes open.
  • Face tracking: Maintain a consistent ID for each face across consecutive frames using the tracking option.

Compatibility

Plugin VersionCapacitor VersionStatus
8.x.x>=8.x.xActive support
7.x.x7.x.xDeprecated
6.x.x6.x.xDeprecated

Installation

You can use our AI-Assisted Setup to install the plugin. Add the Capawesome Skills to your AI tool using the following command:

npx skills add capawesome-team/skills --skill capacitor-plugins

Then use the following prompt:

Use the `capacitor-plugins` skill from `capawesome-team/skills` to install the `@capacitor-mlkit/face-detection` plugin in my project.

If you prefer Manual Setup, install the plugin by running the following commands and follow the platform-specific instructions below:

npm install @capacitor-mlkit/face-detection
npx cap sync

Attention: This plugin only supports CocoaPods for iOS dependency management. Swift Package Manager (SPM) is not supported for the ML Kit SDK, see this comment.

Android

Dependencies

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

If needed, you can define the following project variable in your app’s variables.gradle file to change the default version of the dependency:

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

This can be useful if you encounter dependency conflicts with other plugins in your project.

iOS

Minimum Deployment Target

Make sure to set the deployment target in your ios/App/Podfile to at least 15.5:

platform :ios, '15.5'

Configuration

No configuration required for this plugin.

Demo

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

Usage

The following example shows how to detect faces in an image.

Detect faces in an image

Detect human faces in an image at a local path. You can configure the accuracy/speed trade-off and enable landmarks, contours, classification (smiling and eyes open probabilities), and face tracking. Only available on Android and iOS:

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

const processImage = async () => {
  const { faces } = 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,
  });
  return faces;
};

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 rectangle.5.1.0
topnumberThe Y coordinate of the top of the rectangle.5.1.0
rightnumberThe X coordinate of the right side of the rectangle.5.1.0
bottomnumberThe Y coordinate of the bottom of the rectangle.5.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

FAQ

Which platforms are supported by this plugin?

The processImage(...) method is only available on Android and iOS. The Web platform is not supported by the underlying ML Kit Face Detection SDK.

Does the plugin recognize who is in the picture?

No, the plugin performs face detection, not face recognition. It detects the position of faces in an image along with attributes such as landmarks, contours, head rotation, and smiling probability, but it does not identify individuals. With the enableTracking option you can only maintain a consistent ID for the same face across consecutive frames.

What is the difference between landmarks and contours?

A landmark is a single point on a detected face, such as an eye, nose, or mouth. A contour is a list of points that outlines a facial feature, such as the face oval, eyebrows, eyes, or lips. Landmarks are enabled via the landmarkMode option and contours via the contourMode option. Note that contours are only returned for up to 5 faces.

How can I detect whether a person is smiling or has their eyes open?

Set the classificationMode option to All. The detected faces then contain the smilingProbability, leftEyeOpenProbability, and rightEyeOpenProbability properties, each a value between 0.0 and 1.0.

What is the difference between this plugin and the Face Mesh Detection plugin?

This plugin detects faces with bounding boxes, landmarks, contours, and classifications on Android and iOS. The ML Kit Face Mesh Detection plugin returns a dense mesh of 468 3D points and triangle information for detected faces, but is only available on Android.

Can I use this plugin with Ionic, React, Vue or Angular?

Yes, the plugin is framework-agnostic. It works in any Capacitor app regardless of the web framework, including Ionic with Angular, React, or Vue, as well as plain JavaScript projects.

Terms & Privacy

This plugin uses the Google ML Kit:

Newsletter

Stay up to date with the latest news and updates about the Capawesome, Capacitor, and Ionic ecosystem by subscribing to our Capawesome Newsletter.

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.

版本与发布记录

@capacitor-mlkit/face-detection 共发布 26 个版本,首次发布于 2023/07/21;过去 12 个月发布了 9 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
8.2.2latest2026/10/319 天前
8.2.12026/09/101 个月前
8.1.12026/08/312 个月前
8.1.02026/05/076 个月前
8.0.12026/02/198 个月前
8.0.02025/12/1710 个月前

其他发布通道:next → 7.0.0-next.4,dev → 7.0.0-dev.1765885034。

关于 @capacitor-mlkit/face-detection 的常见问题

@capacitor-mlkit/face-detection 是什么?

Capacitor plugin for ML Kit Face Detection on Android and iOS.

如何安装 @capacitor-mlkit/face-detection?

在项目目录运行 npm install @capacitor-mlkit/face-detection,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@capacitor/core(>=8.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@capacitor-mlkit/face-detection 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@capacitor-mlkit/face-detection 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@capacitor-mlkit/face-detection 可以商用吗?

@capacitor-mlkit/face-detection 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@capacitor-mlkit/face-detection 的下载量有多少?

根据 npm 官方下载统计,@capacitor-mlkit/face-detection 在 2026/10/09 – 2026/11/07 这 30 天内被下载 6,309 次,日均约 210 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@capacitor-mlkit/face-detection 还在维护吗?

最新版本 8.2.2 发布于 2026/10/31(9 天前);至今共发布 26 个版本,其中过去 12 个月发布了 9 个;首次发布于 2023/07/21。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。