processFile method

  1. @override
Future<SegmentationResult> processFile(
  1. String filePath,
  2. Uint8List frameData,
  3. SegmenterInputMetadata metadata
)
override

Process an image file and return segmentation result.

This is more reliable than processFrame as ML Kit can decode the image directly from the file path.

Parameters:

  • filePath: Path to image file (JPEG, PNG, etc.)
  • frameData: Original RGBA frame data for compositing
  • metadata: Image dimensions for mask scaling

Implementation

@override
Future<SegmentationResult> processFile(
  String filePath,
  Uint8List frameData,
  SegmenterInputMetadata metadata,
) async {
  // On iOS/macOS with native initialized, use real segmentation with the file
  if (_supportsNativeSegmentation && _nativeInitialized) {
    try {
      // Read file as bytes and send to native
      final file = File(filePath);
      if (await file.exists()) {
        final imageBytes = await file.readAsBytes();
        return _processWithNativeBytes(imageBytes, frameData, metadata);
      }
    } catch (e) {
      // Fall through to stub
    }
  }

  // Fallback: Return all-white mask
  return _createStubResult(frameData, metadata);
}