create<R> static method

Future<WebVisionTask<R>> create<R>(
  1. String task,
  2. TaskOptions options,
  3. RunningMode runningMode,
  4. Map<String, Object?> settings,
  5. R decode(
    1. Map<String, dynamic> json,
    2. Float64List? landmarks
    ),
)

Creates one official browser task from options in runningMode; settings are the task's own options, named as in Google's JavaScript API, and decode reads each result.

Implementation

static Future<WebVisionTask<R>> create<R>(
  String task,
  TaskOptions options,
  RunningMode runningMode,
  Map<String, Object?> settings,
  R Function(Map<String, dynamic> json, Float64List? landmarks) decode,
) async {
  await loadPackageScript('mediapipe_vision', 'assets/bridge.js');
  final modelBytes = options.modelBytes;
  final modelPath = options.modelPath;
  final id = await _workerResult(
    _create(
      {
            'task': task,
            'delegate': options.delegate.name.toUpperCase(),
            'modelBytes': modelBytes == null
                ? null
                : Uint8List.fromList(modelBytes).toJS,
            'modelPath': modelPath == null
                ? null
                : Uri.base.resolve(modelPath).toString(),
            // Google's browser tasks have no LIVE_STREAM; it runs on their
            // VIDEO graph, with its flow limiter in the task runner.
            'runningMode': runningMode == RunningMode.image
                ? 'IMAGE'
                : 'VIDEO',
            'runtimeBaseUrl': MediaPipeWebRuntime.resolve(Uri.base),
            ...settings,
          }.jsify()!
          as JSObject,
    ),
  );
  return WebVisionTask._(id, decode);
}