segmentMat method
Segments a pre-decoded cv.Mat image.
mat should be a BGR or BGRA cv.Mat (OpenCV format).
The Mat data is transferred efficiently to the worker isolate.
Note: The Mat is NOT disposed by this method.
Returns a SegmentationMask (or MulticlassSegmentationMask for multiclass model) with per-pixel probabilities.
Implementation
Future<SegmentationMask> segmentMat(cv.Mat mat) async {
if (mat.isEmpty) {
throw SegmentationException(
SegmentationError.imageDecodeFailed,
'Input Mat is empty',
);
}
final Uint8List matBytes = mat.data;
final int channels = mat.channels;
final Map result = await sendRequest<Map>('segmentMat', {
'matBytes': TransferableTypedData.fromList([matBytes]),
'width': mat.cols,
'height': mat.rows,
'channels': channels,
});
return _rebuildMask(result);
}