create method

  1. @override
Future<Object> create({
  1. required ModelSource source,
  2. int cpuThreadNum = 4,
  3. CpuPower cpuPower = CpuPower.high,
  4. bool useOpenCL = false,
})
override

Loads models and returns an opaque engine handle.

Implementation

@override
Future<Object> create({
  required ModelSource source,
  int cpuThreadNum = 4,
  CpuPower cpuPower = CpuPower.high,
  bool useOpenCL = false,
}) async {
  final paths = switch (source) {
    FilePathsModelSource s => s,
    BundledModelSource() => throw UnsupportedError(
        'ModelSource.bundled is not yet supported on Android/iOS in v0.2. '
        'Use ModelSource.filePaths(...) and supply .nb files and a dictionary. '
        'See example/lib/main.dart for a download helper.',
      ),
  };
  final id = await methodChannel.invokeMethod<int>(_Channel.create, {
    _Channel.detModelPath: paths.det,
    _Channel.recModelPath: paths.rec,
    _Channel.clsModelPath: paths.cls ?? '',
    _Channel.labelPath: paths.dict,
    _Channel.cpuThreadNum: cpuThreadNum,
    _Channel.cpuPower: cpuPower.value,
    _Channel.useOpenCL: useOpenCL,
  });
  return id!;
}