recognize method

  1. @override
Future<List<OcrResult>> recognize(
  1. Object handle,
  2. Uint8List imageBytes, {
  3. int maxSideLen = 960,
  4. bool runDetection = true,
  5. bool runClassification = false,
  6. bool runRecognition = true,
})
override

Runs OCR on an image encoded in a browser/native-decodable format.

Implementation

@override
Future<List<OcrResult>> recognize(
  Object handle,
  Uint8List imageBytes, {
  int maxSideLen = 960,
  bool runDetection = true,
  bool runClassification = false,
  bool runRecognition = true,
}) async {
  final ocr = handle as _JsOcr;
  final blob = web.Blob(
    [imageBytes.toJS].toJS,
    web.BlobPropertyBag(type: 'image/jpeg'),
  );
  final jsResult = await ocr.predict(blob).toDart;
  final list = jsResult.toDart;
  if (list.isEmpty) return const [];
  final first = list.first;
  final items = first.items;
  if (items == null) return const [];
  return items.toDart.map(_fromJs).toList(growable: false);
}