FlutterMLKIT文本识别提取指定行

qzlgjiam  于 2023-03-13  发布在  Flutter
关注(0)|答案(1)|浏览(169)

如何从Flutter ML Kit文本识别中提取一行?

我想从“SUMME”中提取行,我只需要该行作为双变量,

List recognedText = [];
  bool textScanning = false;
  var scannedText = "Scanned Text will be shown here".obs;
  takeImageforScan() async {
    recognedText.clear();
    try {
      textScanning = true;
      final pickedImage =
          await ImagePicker().pickImage(source: ImageSource.camera);
      if (pickedImage != null) {
        textScanning = true;
        final inputImage = InputImage.fromFilePath(pickedImage.path);
        final recognizer = GoogleMlKit.vision.textRecognizer();
        final visionText = await recognizer.processImage(
          inputImage,
        );
        //scannedText.value = visionText.text;
        recognizer.close();
        textScanning = false;

         for (TextBlock block in visionText.blocks) {
      for (TextLine line in block.lines) {
        recognedText.add(block.text);
        //Extract the Summe Line from the Text
        if (line.text.contains("Summe")) {
          recognedText.add(line.text);
        }
      }
    }
  }
      }
      print(recognedText);
      Get.to(() => const RegisterAutomat());
    } catch (e) {
      print(e);

      textScanning = false;
      Get.snackbar(
          "Fehler", "Keine Daten gefunden,bitte tragen Sie manuell ein");
    }
  }

它实际上返回列表从图像所有的文本,但我想只提取价格从总和(总价),我想我必须提取它从返回的文本列表,或者我可以使它与AI包?输出从Flutter

√  Built build\app\outputs\flutter-apk\app-debug.apk.
I/flutter ( 3895): 0
I/flutter ( 3895): Creating Screen für(1)
I/SurfaceView@c9d0980( 3895): onWindowVisibilityChanged(8) false io.flutter.embedding.android.FlutterSurfaceView{c9d0980 V.E...... ........ 0,0-960,2613} of ViewRootImpl@6c1a062[MainActivity]
I/SurfaceView@c9d0980( 3895): surfaceDestroyed callback.size 1 #2 io.flutter.embedding.android.FlutterSurfaceView{c9d0980 V.E...... ........ 0,0-960,2613}
I/SurfaceView@c9d0980( 3895): windowStopped(true) false io.flutter.embedding.android.FlutterSurfaceView{c9d0980 V.E...... ........ 0,0-960,2613} of ViewRootImpl@6c1a062[MainActivity]
I/SurfaceView@c9d0980( 3895): onWindowVisibilityChanged(0) false io.flutter.embedding.android.FlutterSurfaceView{c9d0980 V.E...... ......ID 0,0-960,2613} of ViewRootImpl@6c1a062[MainActivity]
I/SurfaceView@c9d0980( 3895): windowStopped(false) true io.flutter.embedding.android.FlutterSurfaceView{c9d0980 V.E...... ......ID 0,0-960,2613} of ViewRootImpl@6c1a062[MainActivity]
I/SurfaceView@c9d0980( 3895): surfaceCreated 1 #1 io.flutter.embedding.android.FlutterSurfaceView{c9d0980 V.E...... ......ID 0,0-960,2613}
I/SurfaceView@c9d0980( 3895): surfaceChanged (960,2613) 1 #1 io.flutter.embedding.android.FlutterSurfaceView{c9d0980 V.E...... ......ID 0,0-960,2613}
I/flutter ( 3895): [ETRON Soft wareentwicklungs -und
I/flutter ( 3895): Vertriebs Gmbh, ETRON Soft wareentwicklungs -und
I/flutter ( 3895): Vertriebs Gmbh, Text, Kassa -ID: 152 ("Natalie4")
I/flutter ( 3895): Sitzungs-ID: POS15201-000002
I/flutter ( 3895): Druckdatum: 28.01. 2021 12:00:47
I/flutter ( 3895): Abschluss durch: johann
I/flutter ( 3895): 4 Belege K15201/20- 000053 bis
I/flutter ( 3895): K15201/20 - 000056, Kassa -ID: 152 ("Natalie4")
I/flutter ( 3895): Sitzungs-ID: POS15201-000002
I/flutter ( 3895): Druckdatum: 28.01. 2021 12:00:47
I/flutter ( 3895): Abschluss durch: johann
I/flutter ( 3895): 4 Belege K15201/20- 000053 bis
I/flutter ( 3895): K15201/20 - 000056, Kassa -ID: 152 ("Natalie4")
I/flutter ( 3895): Sitzungs-ID: POS15201-000002
I/flutter ( 3895): Druckdatum: 28.01. 2021 12:00:47
I/flutter ( 3895): Abschluss durch: johann
I/flutter ( 3895): 4 Belege K15201/20- 000053 bis
I/flutter ( 3895): K15201/20 - 000056, Kassa -ID: 152 ("Natalie4")
I/flutter ( 3895): Sitzungs-ID: POS15201-000002
I/flutter ( 3895): Druckdatum: 28.01. 2021 12:00:47
I/flutter ( 3895): Abschluss durch: johann
I/flutter ( 3895): 4 Belege K15201/20- 000053 bis
I/flutter ( 3895): K15201/20 - 000056, Kassa -ID: 152 ("Natalie4")
I/flutter ( 3895): Sitzungs-ID: POS15201-000002
I/flutter ( 3895): Druckdatum: 28.01. 2021 12:00:47
I/flutter ( 3895): Abschluss durch: johann
I/flutter ( 3895): 4 Belege K15201/20- 000053 bis
I/flutter ( 3895): K15201/20 - 000056, Kassa -ID: 152 ("Natalie4")
I/flutter ( 3895): Sitzungs-ID: POS15201-000002
I/flutter ( 3895): Druckdatum: 28.01. 2021 12:00:47
I/flutter ( 3895): Abs
jgwigjjp

jgwigjjp1#

免责声明-我不知道Flutter
查看您的代码,您有

for (TextBlock block in visionText.blocks) {

这在的文本上循环,而不是“行”。例如,图像“头”中的所有文本可能是“一块”,但不一定是“多行”
但是你有

for (TextLine line in block.lines) {

这将在该块中找到的所有换行符上循环。
然后,图像识别找到的文本是区分大小写的,因此您需要

if (line.text.contains("SUMME")) {

但是,不能保证5.401,73在同一个line上,甚至在同一个block上,因为图像包含多个文本块。您需要做更多的调试来找到该编号存在的块。
而且您的映像中有多个SUMME。因此,您还应该检查包含Umsatz的块/行。

if (block.lines[0].text.contains("Umsatz")) {
  for (TextLine line in block.lines) {
    if (line.text.contains("SUMME")) {
       print(line.text);
    }
  }
}

相关问题