flutter-ml / google_ml_kit_flutter

A flutter plugin that implements Google's standalone ML Kit
MIT License
958 stars 737 forks source link

google_mlkit_text_recognition: ^0.13.1 unable to return OCR of arabic verse. #686

Open adnankhan74444 opened 3 weeks ago

adnankhan74444 commented 3 weeks ago

Describe your issue. If applicable, add screenshots to help explain your problem.

Future<void> recognizeArabicText(File imageFile) async {
  final inputImage = InputImage.fromFile(imageFile);
  final textRecognizer = TextRecognizer(script: TextRecognitionScript.latin);

  try {
    final recognizedTextResult = await textRecognizer.processImage(inputImage);
    print('RecognizedTextResult: ${recognizedTextResult.text}');
  } catch (e) {
    print('Error during text recognition: $e');
  } finally {
    textRecognizer.close();
  }
}

Future<File> getImageFileFromAssets(String path) async {
  final byteData = await rootBundle.load('assets/$path');
  final file = File('${(await getTemporaryDirectory()).path}/$path');
  await file.create(recursive: true);
  await file.writeAsBytes(byteData.buffer
      .asUint8List(byteData.offsetInBytes, byteData.lengthInBytes));
  return file;
}

Future<void> getOCRText() async {
  var assetsFile = await getImageFileFromAssets('002.png');
  print('Loaded image: ${assetsFile.path}, Size: ${await assetsFile.length()} bytes');
  await recognizeArabicText(assetsFile);
}

recognizedTextResult.text always return empty.

002

Steps to reproduce.

Future<void> recognizeArabicText(File imageFile) async {
  final inputImage = InputImage.fromFile(imageFile);
  final textRecognizer = TextRecognizer(script: TextRecognitionScript.latin);

  try {
    final recognizedTextResult = await textRecognizer.processImage(inputImage);
    print('RecognizedTextResult: ${recognizedTextResult.text}');
  } catch (e) {
    print('Error during text recognition: $e');
  } finally {
    textRecognizer.close();
  }
}

Future<File> getImageFileFromAssets(String path) async {
  final byteData = await rootBundle.load('assets/$path');
  final file = File('${(await getTemporaryDirectory()).path}/$path');
  await file.create(recursive: true);
  await file.writeAsBytes(byteData.buffer
      .asUint8List(byteData.offsetInBytes, byteData.lengthInBytes));
  return file;
}

Future<void> getOCRText() async {
  var assetsFile = await getImageFileFromAssets('002.png');
  print('Loaded image: ${assetsFile.path}, Size: ${await assetsFile.length()} bytes');
  await recognizeArabicText(assetsFile);
}

recognizedTextResult.text always return empty.

002

What is the expected result?

It should return the result

Did you try our example app?

Yes

Is it reproducible in the example app?

Yes

Reproducible in which OS?

Android, iOS and Android

Flutter/Dart Version?

No response

Plugin Version?

google_mlkit_text_recognition: ^0.13.1

adnankhan74444 commented 1 week ago

@bensonarafat any update on this?