recognizeImageBytes method

  1. @override
Future<List<OcrResult>> recognizeImageBytes(
  1. Uint8List imageBytes, {
  2. OcrOptions? options,
})
override

从图片字节数据识别文字。

Implementation

@override
Future<List<OcrResult>> recognizeImageBytes(
  Uint8List imageBytes, {
  OcrOptions? options,
}) async {
  final engine = _requiredEngine;
  final bindings = PpOcrFfiBindings.instance;
  final PpOcrResultArrayC resultC;
  if (options == null) {
    resultC = bindings.recognizeBytes(engine, imageBytes);
  } else {
    final optsPtr = options.toNativeStruct();
    try {
      resultC = bindings.recognizeBytesEx(engine, imageBytes, optsPtr);
    } finally {
      calloc.free(optsPtr);
    }
  }

  if (resultC.error != nullptr) {
    final err = resultC.error.toDartString();
    throw Exception('OCR recognition failed: $err');
  }

  return _parseResultsC(resultC);
}