khjde1207 / tesseract_ocr

Tesseract OCR for flutter
BSD 3-Clause "New" or "Revised" License
62 stars 31 forks source link

"Failed to create image decoder" and other Java exceptions #13

Closed TheLastGimbus closed 2 years ago

TheLastGimbus commented 2 years ago

Hi there!

I'm recently testing this lib on large number of images - I was scanning about 1k of them, and this error kept ocuring on one of them:

08-22 11:34:05.015 25468 25885 D skia    : --- Failed to create image decoder with message 'unimplemented'
08-22 11:34:05.015 25468 25885 E ReadFile: Cannot decode bitmap
--------- beginning of crash
08-22 11:34:05.016 25468 25885 E AndroidRuntime: FATAL EXCEPTION: Thread-29
08-22 11:34:05.016 25468 25885 E AndroidRuntime: Process: com.example.myapp, PID: 25468
08-22 11:34:05.016 25468 25885 E AndroidRuntime: java.lang.RuntimeException: Failed to read image file
08-22 11:34:05.016 25468 25885 E AndroidRuntime:    at com.googlecode.tesseract.android.TessBaseAPI.g(Unknown Source:27)
08-22 11:34:05.016 25468 25885 E AndroidRuntime:    at g.b.a.b.run(Unknown Source:4)
08-22 11:34:05.016 25468 25885 E AndroidRuntime:    at java.lang.Thread.run(Thread.java:919)
08-22 11:34:05.090 25468 25885 I Process : Sending signal. PID: 25468 SIG: 9

Sadly, I didn't collect the image itself to see what's wrong, but that's not very important - this completley crashes the app, giving you no way to handle it

Can we just try-catch any Java exceptions (at least in run):

https://github.com/khjde1207/tesseract_ocr/blob/668a1a7dcb42a444c9578309d3768fa7b781693b/android/src/main/java/io/paratoner/flutter_tesseract_ocr/FlutterTesseractOcrPlugin.java#L91-L101

...and pass them to Dart?

khjde1207 commented 2 years ago

Try-catch will be added. If possible, please upload an error image as well.

TheLastGimbus commented 2 years ago

Thanks! By the way, again - I would be happy to contribute to this plugin because I will use it a lot - I know Java and Kotlin good enough - if there is something I can help with, let me know!

When do you plan to add "Live OCR" (as you named it) in Android?

(In addition to what I wrote in #4 ) When scanning multiple images, I get this:

W/TessBaseAPI(27912): TessBaseAPI was not terminated using recycle()

But it doesn't crash anything :monocle_face: it would be nice to have more control over tesseract's lifecycle in general :ok_hand:

I will want to scan stuff on 2 threads simontanuesly - for now, it works nice :ok_hand: - please implement "Live OCR" with this in mind if you may :pray:

Thanks again!

khjde1207 commented 2 years ago

Converting from Android to CameraImage -> Bytes throws an error. I couldn't find a solution. https://github.com/khjde1207/tesseract_ocr/blob/b32202837723ffe572fa7905a43ddbd5706af5ef/example/lib/camera_view.dart#L737

khjde1207 commented 2 years ago

original logic : https://github.com/hazem-saeed/tesseract_ocr/blob/a815ddfadf9dc4b291c76b950aa8887b1550d6a4/android/src/main/java/io/paratoner/tesseract_ocr/TesseractOcrPlugin.java#L76

Logic I modified : https://github.com/khjde1207/tesseract_ocr/blob/b32202837723ffe572fa7905a43ddbd5706af5ef/android/src/main/java/io/paratoner/flutter_tesseract_ocr/FlutterTesseractOcrPlugin.java#L102

https://github.com/adaptech-cz/Tesseract4Android/issues/22

I used the latest version of Tesseract4Android because of this error. The end function is gone in the latest version. calling the stop function. this seems to be the problem

TheLastGimbus commented 2 years ago

I found the image! It was 0 bytes empty file :joy: I added if in my code to skip those...