Getting UnsatisfiedLinkError: no jnilept in java.library.path when I create TessBaseAPI

前端 未结 1 1875
梦毁少年i
梦毁少年i 2020-12-31 17:44

I am new to java cpp and tesseract-ocr. I am stuck with one issue from couple of hours. I am getting UnsatisfiedLinkError: no jnilept in java.library.path when I cre

1条回答
  •  时光说笑
    2020-12-31 18:21

    you could clone or download the project:

    https://github.com/bytedeco/javacpp-presets#the-cppbuildsh-scripts

    then build the modules: JavaCPP Presets for Tesseract and JavaCPP Presets for Leptonica;

    (to build the leptonica project you maybe need to install nasm https://www.nasm.us/)

    (to build the entire javacpp-presets project you also have to install cmake)

    that would create the native libraries:

    libjnilept.so and libjnitesseract.so

    then you have to specify the jni.library.path

    You can do it with:

    System.setProperty(JAVA_LIBRARY_PATH, tmpDirName);
    /* Optionally add these two lines */
    System.setProperty("jna.library.path", tmpDirName);
    System.setProperty("jni.library.path", tmpDirName);
    final Field fieldSysPath;
    
    fieldSysPath = ClassLoader.class.getDeclaredField(SYS_PATHS);
    
    fieldSysPath.setAccessible(true);
    fieldSysPath.set(null, null);
    

    (you could instead specify the -Djava.library.path= on the virtual machine options)

    you only have to put the generated files: libjnilept.so and libjnitesseract.so in some folder and set this path for: jni.library.path

    
        org.bytedeco.javacpp-presets
        tesseract           
        4.0.0-1.4.4            
    
    
    
        org.bytedeco.javacpp-presets
        leptonica
        1.77.0-1.4.4 
    
    

    you can also try to add

        
        org.bytedeco.javacpp-presets
        leptonica-platform 
        1.77.0-1.4.4
     
    
    
        org.bytedeco.javacpp-presets
        tesseract-platform
        4.0.0-1.4.4
    
    

    and add into the build a maven-assembly-plugin

    
            
                maven-assembly-plugin
                
                    
                        
                             mainClass>fully.qualified.MainClass
                        
                    
                    
                        jar-with-dependencies
                    
                
                
                
                    
                        make-assembly 
                        package 
                        
                            single 
                        
                    
                
               
    
    

     


     

    Also, you could also get an error like this:

    sscanf(line, "%" QUOTED_TOKENSIZE "s %" QUOTED_TOKENSIZE "s %f %f",
    linear_token, essential_token, &ParamDesc[i].Min, &ParamDesc[i].Max) == 4
    :Error:Assert failed:in file clusttool.cpp, line 73
    #
    # A fatal error has been detected by the Java Runtime Environment:
    

    Due to Tesseract's locale requirements, export LC_ALL=C is required before running any client programs.

    so:

           
                org.codehaus.mojo
                exec-maven-plugin
                1.6.0
                
                    
                        
                            exec
                        
                    
                
                 
                      
                        C
                    
                    java
                    
                        -classpath
                        
                        ${classpath}
                    
                
             
    

    source:
        - https://github.com/nguyenq/tess4j/issues/106
        - https://github.com/sirfz/tesserocr/issues/165

    0 讨论(0)
提交回复
热议问题