I want scan image for getting text, but when I send image to render app crashes and I lose connection to device

154

I solved this issue for myself like this =>

  1. Add GoogleService-Info.plist to Runner
  2. add FirebaseCore to dependencies
  3. open xCode and do some changes in AppDelegate.swift
import UIKit
import Flutter
import FirebaseCore

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
      FirebaseApp.configure()
    GeneratedPluginRegistrant.register(with: self)
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
}
Share:
154
Lala Naibova
Author by

Lala Naibova

I'm a mobile developer

Updated on January 03, 2023

Comments

  • Lala Naibova
    Lala Naibova over 1 year

    I'm using "google_ml_kit" package

    Future pickImage() async {
        final file = await _imagePicker.pickImage(source: ImageSource.gallery);
        setImage(File(file!.path));
        await textDetector(image!);
      }
    

    I haven't any problem about picking image, but when code line entering to the recognisedText app crashes and I get -- Lost connection to device.

    textDetector(File file) async {
        final inputImage = InputImage.fromFile(file);
        final textDetector = GoogleMlKit.vision.textDetector();
        final RecognisedText recognisedText =
            await textDetector.processImage(inputImage);
    
        String text = recognisedText.text;
        for (TextBlock block in recognisedText.blocks) {
          final Rect rect = block.rect;
          final List<Offset> cornerPoints = block.cornerPoints;
          final String text = block.text;
          final List<String> languages = block.recognizedLanguages;
    
          for (TextLine line in block.lines) {
            // Same getters as TextBlock
            for (TextElement element in line.elements) {
              // Same getters as TextBlock
            }
          }
        }
    
        textDetector.close();
      }
    

    App crashes in this part

    /// Function that takes [InputImage] processes it and returns a [RecognisedText] object.
      Future<RecognisedText> processImage(InputImage inputImage) async {
        _hasBeenOpened = true;
        final result = await Vision.channel.invokeMethod('vision#startTextDetector',
            <String, dynamic>{'imageData': inputImage._getImageData()});
    
        final recognisedText = RecognisedText.fromMap(result);
    
        return recognisedText;
      }
    

    When I run app via device :

    *** Terminating app due to uncaught exception 'FIRAppNotConfigured', reason: 'The default Firebase app instance must be configured. To configure, call `[FIRApp configure];` (`FirebaseApp.configure()` in Swift) in the App Delegate's `application:didFinishLaunchingWithOptions:` (`application(_:didFinishLaunchingWithOptions:)` in Swift).'
    *** First throw call stack:
    (0x1804d9c9c 0x19768d758 0x18052cd04 0x103ca6fe8 0x103ca885c 0x103ca87dc 0x102b59e8c 0x102b5a0dc 0x102b5a5fc 0x102cbe9f4 0x102cbde8c 0x102cbe0e4 0x102cbc548 0x102cbc3ec 0x1045efbcc 0x106adce4c 0x106adccd8 0x106ad8418 0x10c06994c 0x10bbba120 0x10bf36aec 0x10be64204 0x10be67f5c 0x1804edfcc 0x180478338 0x180472fcc 0x180452ea4 0x180465d7c 0x19a6da9a0 0x182c9805c 0x182a2dce0 0x102b58abc 0x109474190)
    libc++abi: terminating with uncaught exception of type NSException
    * thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
        frame #0: 0x00000001b9f429e8 libsystem_kernel.dylib`__pthread_kill + 8
    libsystem_kernel.dylib`__pthread_kill:
    ->  0x1b9f429e8 <+8>:  b.lo   0x1b9f42a04               ; <+36>
        0x1b9f429ec <+12>: stp    x29, x30, [sp, #-0x10]!
        0x1b9f429f0 <+16>: mov    x29, sp
        0x1b9f429f4 <+20>: bl     0x1b9f3e670               ; cerror_nocancel
    Target 0: (Runner) stopped.
    Lost connection to device.
    
    • Dong Chen
      Dong Chen about 2 years
      The "google_ml_kit" package is neither owned nor endorsed by either Google or ML Kit team. You should report issues on their support site: github.com/bharat-biradar/Google-Ml-Kit-plugin/issues
    • Lala Naibova
      Lala Naibova about 2 years
      yeah, I did. Do you have any suggestion about package for text recognizing ?