Unofficial Capacitor plugin for ML Kit Subject Segmentation.1
npm install @capacitor-mlkit/subject-segmentation
npx cap sync
This plugin requires a minimum API level of 24.
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" -->
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;
};
processImage(...)
isGoogleSubjectSegmentationModuleAvailable()
installGoogleSubjectSegmentationModule()
addListener('googleSubjectSegmentationModuleInstallProgress', ...)
removeAllListeners()
- Interfaces
- Enums
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() => 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() => 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(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() => Promise<void>
Remove all listeners for this plugin.
Only available on Android.
Since: 7.2.0
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 |
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 |
Prop | Type | Description | Since |
---|---|---|---|
available |
boolean |
Whether or not the Google Subject Segmentation module is available. | 7.2.0 |
Prop | Type |
---|---|
remove |
() => Promise<void> |
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 |
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 |
This plugin uses the Google ML Kit:
See CHANGELOG.md.
See LICENSE.
Footnotes
-
This project is not affiliated with, endorsed by, sponsored by, or approved by Google LLC or any of their affiliates or subsidiaries. ↩