encodeAsync method
Future<Float32List>
encodeAsync(
- VisionImageInput image, {
- void capture(
- String stage,
- Float32List rows
- void checkCancelled()?,
- void onProgress()?,
Same arithmetic as encode, yielding to the event loop between stages.
checkCancelled may throw to abort before the next stage is computed.
A stage itself is synchronous CPU work; run inference in a worker isolate
when integrating with a UI.
Implementation
Future<Float32List> encodeAsync(
VisionImageInput image, {
void Function(String stage, Float32List rows)? capture,
void Function()? checkCancelled,
void Function(int completed, int total)? onProgress,
}) async {
await Future<void>.delayed(Duration.zero);
checkCancelled?.call();
Float32List? result;
var completed = 0;
for (final (stage, rows) in _stages(image)) {
capture?.call(stage, Float32List.fromList(rows));
result = rows;
onProgress?.call(++completed, config.vision.numLayers + 2);
await Future<void>.delayed(Duration.zero);
checkCancelled?.call();
}
return result!;
}