components/background_components/mlkit_segmenter_stub library
ML Kit Selfie Segmentation Integration
This file provides a reference implementation for integrating Google ML Kit Selfie Segmentation with the VirtualBackgroundProcessor.
Setup
- Add to pubspec.yaml:
dependencies:
google_mlkit_selfie_segmentation: ^0.6.0
- For Android, add to android/app/build.gradle:
android {
defaultConfig {
minSdkVersion 21
}
}
- For iOS, add to ios/Podfile:
platform :ios, '12.0'
React Comparison
React uses @mediapipe/selfie_segmentation:
selfieSegmentation = new SelfieSegmentation({
locateFile: (file) =>
`https://cdn.jsdelivr.net/npm/@mediapipe/selfie_segmentation/${file}`,
});
selfieSegmentation.setOptions({
modelSelection: 1, // 0 = general, 1 = landscape (faster)
selfieMode: false,
});
selfieSegmentation.onResults((results) => {
// results.segmentationMask - the mask image
// results.image - the original image
});
Flutter ML Kit equivalent:
final segmenter = SelfieSegmenter(mode: SegmenterMode.stream);
final mask = await segmenter.processImage(inputImage);
// mask.confidences[i] - confidence value per pixel
Classes
- StubBackgroundSegmenter
- Stub implementation of BackgroundSegmenter for platforms without ML Kit.
Extensions
- FrameConversion on Uint8List
- Extension to help with frame conversion for ML Kit.