getSegmentationMask method

Future<SegmentationMask> getSegmentationMask(
  1. Uint8List imageBytes, {
  2. IsolateOutputFormat outputFormat = IsolateOutputFormat.float32,
  3. double binaryThreshold = 0.5,
})

Segments an image to separate foreground (people) from background.

Returns a SegmentationMask with per-pixel probabilities indicating foreground vs background.

Parameters:

Throws StateError if initializeSegmentation hasn't been called. Throws SegmentationException on inference failure.

Implementation

Future<SegmentationMask> getSegmentationMask(
  Uint8List imageBytes, {
  IsolateOutputFormat outputFormat = IsolateOutputFormat.float32,
  double binaryThreshold = 0.5,
}) async {
  _requireReady();
  _requireSegmentationReady();
  final Map<String, dynamic> result =
      await _sendSegmentationRequest<Map<String, dynamic>>('segment', {
        'bytes': TransferableTypedData.fromList([imageBytes]),
        'outputFormat': outputFormat.index,
        'binaryThreshold': binaryThreshold,
      });
  return _deserializeMask(result);
}