Capacitor plugin for ML Kit Subject Segmentation.
npm install @capacitor-mlkit/subject-segmentationUnofficial Capacitor plugin for ML Kit Subject Segmentation.[^1]
| Plugin Version | Capacitor Version | Status |
| -------------- | ----------------- | -------------- |
| 8.x.x | >=8.x.x | Active support |
``bash`
npm install @capacitor-mlkit/subject-segmentation
npx cap sync
#### 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:
`xml`
You also need to add the following meta data in the application tag in your AndroidManifest.xml:
`xml`
`typescript
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
`typescript`
processImage(options: ProcessImageOptions) => Promise
Performs segmentation on an input image.
Only available on Android and iOS.
| Param | Type |
| ------------- | ------------------------------------------------------------------- |
| options | ProcessImageOptions |
Returns: Promise<ProcessImageResult>
Since: 7.2.0
--------------------
`typescript`
isGoogleSubjectSegmentationModuleAvailable() => Promise
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
--------------------
`typescript`
installGoogleSubjectSegmentationModule() => Promise
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
--------------------
`typescript`
addListener(eventName: 'googleSubjectSegmentationModuleInstallProgress', listenerFunc: (event: GoogleSubjectSegmentationModuleInstallProgressEvent) => void) => Promise
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
--------------------
`typescript`
removeAllListeners() => Promise
Remove all listeners for this plugin.
Only available on Android.
Since: 7.2.0
--------------------
#### 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
| | widthnumber | Scale the image to this height. If no 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 |
#### 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 |
This plugin uses the Google ML Kit:
- Terms & Privacy
- Android Data Disclosure
- iOS Data Disclosure
See CHANGELOG.md.
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.