Skip to content

Latest commit

 

History

History

subject-segmentation

@capacitor-mlkit/subject-segmentation

Unofficial Capacitor plugin for ML Kit Subject Segmentation.1

Installation

npm install @capacitor-mlkit/subject-segmentation
npx cap sync

Android

API level

This plugin requires a minimum API level of 24.

Permissions

This API requires the following permissions be added to your AndroidManifest.xml before the application tag:

<uses-permission android:name="android.permission.CAMERA" />

You also 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="subject_segment"/>
<!-- To use multiple models: android:value="face,model2,model3" -->

Usage

import { SubjectSegmentation } from '@capacitor-mlkit/subject-segmentation';

const processImage = async () => {
  const { path } = await SubjectSegmentation.processImage({
    path: 'path/to/image.jpg',
    confidence: 0.7,
  });
  return path;
};

API

processImage(...)

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

Performs segmentation on an input image.

Only available on Android and iOS.

Param Type
options ProcessImageOptions

Returns: Promise<ProcessImageResult>

Since: 7.2.0


isGoogleSubjectSegmentationModuleAvailable()

isGoogleSubjectSegmentationModuleAvailable() => Promise<IsGoogleSubjectSegmentationModuleAvailableResult>

Check if the Google Subject Segmentation module is available.

If the Google Subject Segmentation module is not available, you can install it by using installGoogleSubjectSegmentationModule().

Only available on Android.

Returns: Promise<IsGoogleSubjectSegmentationModuleAvailableResult>

Since: 7.2.0


installGoogleSubjectSegmentationModule()

installGoogleSubjectSegmentationModule() => Promise<void>

Install the Google Subject Segmentation module.

Attention: This only starts the installation. The googleSubjectSegmentationModuleInstallProgress event listener will notify you when the installation is complete.

Only available on Android.

Since: 7.2.0


addListener('googleSubjectSegmentationModuleInstallProgress', ...)

addListener(eventName: 'googleSubjectSegmentationModuleInstallProgress', listenerFunc: (event: GoogleSubjectSegmentationModuleInstallProgressEvent) => void) => Promise<PluginListenerHandle>

Called when the Google Subject Segmentation module is installed.

Only available on Android.

Param Type
eventName 'googleSubjectSegmentationModuleInstallProgress'
listenerFunc (event: GoogleSubjectSegmentationModuleInstallProgressEvent) => void

Returns: Promise<PluginListenerHandle>

Since: 7.2.0


removeAllListeners()

removeAllListeners() => Promise<void>

Remove all listeners for this plugin.

Only available on Android.

Since: 7.2.0


Interfaces

ProcessImageResult

Prop Type Description Since
path string The path to the segmented image file. 7.2.0
width number Returns the width of the image file. 7.2.0
height number Returns the height of the image file. 7.2.0

ProcessImageOptions

Prop Type Description Default Since
path string The local path to the image file. 7.2.0
width number Scale the image to this width. If no height is given, it will respect the aspect ratio. 7.2.0
height number Scale the image to this height. If no width is given, it will respect the aspect ratio. 7.2.0
confidence number Sets the confidence threshold. 0.9 7.2.0

IsGoogleSubjectSegmentationModuleAvailableResult

Prop Type Description Since
available boolean Whether or not the Google Subject Segmentation module is available. 7.2.0

PluginListenerHandle

Prop Type
remove () => Promise<void>

GoogleSubjectSegmentationModuleInstallProgressEvent

Prop Type Description Since
state GoogleSubjectSegmentationModuleInstallState The current state of the installation. 7.2.0
progress number The progress of the installation in percent between 0 and 100. 7.2.0

Enums

GoogleSubjectSegmentationModuleInstallState

Members Value Since
UNKNOWN 0 7.2.0
PENDING 1 7.2.0
DOWNLOADING 2 7.2.0
CANCELED 3 7.2.0
COMPLETED 4 7.2.0
FAILED 5 7.2.0
INSTALLING 6 7.2.0
DOWNLOAD_PAUSED 7 7.2.0

Terms & Privacy

This plugin uses the Google ML Kit:

Changelog

See CHANGELOG.md.

License

See LICENSE.

Footnotes

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