3

I have followed building instructions for tess-two on Github

I build tess-two using NDK successfully and imported the library I am trying to run the test application provided on the same repository but whenever the application starts it gives the following exception: That error is caused once new TessBaseAPI(); is called.

dlopen("/data/app-lib/com.datumdroid.android.ocr.simple-2/liblept.so") failed: Cannot load library: soinfo_link_image(linker.cpp:1635): could not load library "libpng.so" needed by "liblept.so"; caused by load_library(linker.cpp:745): library "libpng.so" not found

Can anyone help with that?

Anirudh Sharma
  • 7,968
  • 13
  • 40
  • 42
  • 1
    Are you sure you're not using precompiled versions of liblept.so and libtess.so? Alongside those files in the tess-two libs folder there should be a file named libpng.so. – rmtheis Aug 05 '15 at 14:09
  • 1
    @rmtheis I'm not sure since when tess-two depends on libpng (we're using it without it), but for me it seems like `System.loadLibrary("png")` call is missing in `TessBaseAPI`. Maybe you should try that before `new TessBaseAPI()` – Dmitry Zaytsev Aug 05 '15 at 14:12
  • @DmitryZaitsev You're right, it should be loaded explicitly using `System.loadLibrary`. This seems to be an issue only on some 4.x versions of Android. Would you please add that suggestion as an answer? – rmtheis Aug 05 '15 at 14:47

2 Answers2

4

I have followed suggestion of Dmitry Zaitsev & thannks to him , solved my problem also .

Please update your TessBaseAPI.java from tess-two library project as below :

   static {
        System.loadLibrary("png");
        System.loadLibrary("lept");
        System.loadLibrary("tess");

        nativeClassInit();
     }

Build tess-two project after updating these file . In my case I have build it using eclipse. Hope it should solve your problem as well.

Deep Shah
  • 1,334
  • 3
  • 20
  • 41
  • 1
    Or better, make a pull request to original tess-two project :) – Dmitry Zaytsev Aug 06 '15 at 07:23
  • 2
    I've made this [change](https://github.com/rmtheis/tess-two/commit/ab1b1c81f4aea21c300736a7df186673a1bcd480) to the tess-two code. All versions of Android should now be able to see libpng. You can do a `git pull` in your tess-two directory to bring in the changes. No need to re-run your ndk-build. – rmtheis Aug 06 '15 at 19:13
  • This solved my problem. Had to include System.loadLibrary("jpgt") also. – pavithraCS Mar 24 '16 at 08:33
2

It seems like System.loadLibrary("png") call is missing in TessBaseAPI, therefore library can't be found.

Try to call System.loadLibrary("png") before calling new TessBaseAPI(). Typically this is done in static initialization block, like so:

public class MyClass {

    static {
        System.loadLibrary("png");
    }

    public void doStuff() {
        new TessBaseAPI();
    }
}
Dmitry Zaytsev
  • 23,650
  • 14
  • 92
  • 146