0

使用 Android Studio,我编写了一个实验性应用程序,它从通过 JNI 本地运行的 C++ 代码中运行 OpenCV。我在基本 OpenCV 中尝试的一切都按预期工作。

现在我想尝试使用 OpenCV Contrib 中的“文本”模块。即 OCR / Tesseract 模块。出于某种原因,我无处可去。

据我了解,这个库有几个版本。一个叫 tess4j,另一个叫 tess-two,然后是 opencv-contrib。最后一个是最好的选择吗?

任何指针?

一个好人制作了一个示例,我下载了https://github.com/pethoalpar/AndroidOpenCvTesseractGetTextFromImage ,它确实为我构建,但在运行它时不起作用(在我的手机 S8+ 上)。

我明白了:

05-27 17:15:26.371 411-411/? E/Zygote: isWhitelistProcess - Process is Whitelisted
05-27 17:15:26.372 411-411/? E/libpersona: scanKnoxPersonas
    Couldn't open the File - /data/system/users/0/personalist.xml - No such file or directory
05-27 17:15:26.373 411-411/? W/SELinux: SELinux selinux_android_compute_policy_index : Policy Index[2],  Con:u:r:zygote:s0 RAM:SEPF_SM-G955F_8.0.0_0002, [-1 -1 -1 -1 0 1]
05-27 17:15:26.374 411-411/? I/SELinux: SELinux: seapp_context_lookup: seinfo=untrusted, level=s0:c512,c768, pkgname=com.pethoalpar.myapplication 
05-27 17:15:26.377 411-411/? I/zygote64: Late-enabling -Xcheck:jni
05-27 17:15:26.406 411-411/? D/TimaKeyStoreProvider: TimaKeyStore is not enabled: cannot add TimaSignature Service and generateKeyPair Service
05-27 17:15:26.407 411-411/? D/ActivityThread: Added TimaKeyStore provider
05-27 17:15:26.588 411-416/com.pethoalpar.myapplication I/zygote64: Do partial code cache collection, code=30KB, data=21KB
    After code cache collection, code=30KB, data=21KB
    Increasing code cache capacity to 128KB
05-27 17:15:26.598 411-434/com.pethoalpar.myapplication I/vndksupport: sphal namespace is not configured for this process. Loading /vendor/lib64/egl/libGLES_mali.so from the current namespace instead.
05-27 17:15:26.601 411-411/com.pethoalpar.myapplication I/InstantRun: starting instant run server: is main process
05-27 17:15:26.622 411-434/com.pethoalpar.myapplication D/libEGL: loaded /vendor/lib64/egl/libGLES_mali.so
05-27 17:15:26.765 411-411/com.pethoalpar.myapplication D/OpenCV/StaticHelper: Trying to get library list
05-27 17:15:26.774 411-411/com.pethoalpar.myapplication E/OpenCV/StaticHelper: OpenCV error: Cannot load info library for OpenCV
05-27 17:15:26.774 411-411/com.pethoalpar.myapplication D/OpenCV/StaticHelper: Library list: ""
    First attempt to load libs
    Trying to init OpenCV libs
    Trying to load library opencv_java3
05-27 17:15:26.775 411-411/com.pethoalpar.myapplication D/OpenCV/StaticHelper: Cannot load library "opencv_java3"
05-27 17:15:26.775 411-411/com.pethoalpar.myapplication W/System.err: java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.pethoalpar.myapplication-xdmsHX5km2PWImYxDfnyhQ==/base.apk", zip file "/data/app/com.pethoalpar.myapplication-xdmsHX5km2PWImYxDfnyhQ==/split_lib_dependencies_apk.apk", zip file "/data/app/com.pethoalpar.myapplication-xdmsHX5km2PWImYxDfnyhQ==/split_lib_slice_0_apk.apk", zip file "/data/app/com.pethoalpar.myapplication-xdmsHX5km2PWImYxDfnyhQ==/split_lib_slice_1_apk.apk", zip file "/data/app/com.pethoalpar.myapplication-xdmsHX5km2PWImYxDfnyhQ==/split_lib_slice_2_apk.apk", zip file "/data/app/com.pethoalpar.myapplication-xdmsHX5km2PWImYxDfnyhQ==/split_lib_slice_3_apk.apk", zip file "/data/app/com.pethoalpar.myapplication-xdmsHX5km2PWImYxDfnyhQ==/split_lib_slice_4_apk.apk", zip file "/data/app/com.pethoalpar.myapplication-xdmsHX5km2PWImYxDfnyhQ==/split_lib_slice_5_apk.apk", zip file "/data/app/com.pethoalpar.myapplication-xdmsHX5km2PWImYxDfnyhQ==/split_lib_slice_6_apk.apk", zip file "/data/app/com.pethoalpar.myapplication-xdmsHX5km2PWImYxDfnyhQ==/split_lib_slice_7_apk.apk", zip file "/data/app/com.pethoalpar.myapplication-xdmsHX5km2PWImYxDfnyhQ==/split_lib_slice_8_apk.apk", zip file "/data/app/com.pethoalpar.myapplication-xdmsHX5km2PWImYxDfnyhQ==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.pethoalpar.myapplication-xdmsHX5km2PWImYxDfnyhQ==/lib/arm64, /data/app/com.pethoalpar.myapplication-xdmsHX5km2PWImYxDfnyhQ==/base.apk!/lib/arm64-v8a, /data/app/com.pethoalpar.myapplication-xdmsHX5km2PWImYxDfnyhQ==/split_lib_dependencies_apk.apk!/lib/arm64-v8a, /data/app/com.pethoalpar.myapplication-xdmsHX5km2PWImYxDfnyhQ==/split_lib_slice_0_apk.apk!/lib/arm64-v8a, /data/app/com.pethoalpar.myapplication-xdmsHX5km2PWImYxDfnyhQ==/split_lib_slice_1_apk.apk!/lib/arm64-v8a, /data/app/com.pethoalpar.myapplication-xdmsHX5km2PWImYxDfnyhQ==/split_lib_slice_2_apk.apk!/lib/arm64-v8a, /data/app/com.pethoalpar.myapplication-xdmsHX5km2PWImYxDfnyhQ==/split_lib_slice_3_apk.apk!/lib/arm64-v8a, /data/app/com.pethoalpar.myapplication-xdmsHX5km2PWImYxDfnyhQ==/split_lib_slice_4_apk.apk!/lib/arm64-v8a, /data/app/com.pethoalpar.myapplication-xdmsHX5km2PWImYxDfnyhQ==/split_lib_slice_5_apk.apk!/lib/arm64-v8a, /data/app/com.pethoalpar.myapplication-xdmsHX5km2PWImYxDfnyhQ==/split_lib_slice_6_apk.apk!/lib/arm64-v8a, /data/app/com.pethoalpar.myapplication-xdmsHX5km2PWImYxDfnyhQ==/split_lib_slice_7_apk.apk!/lib/arm64-v8a, /data/app/com.pethoalpar.myapplication-xdmsHX5km2PWImYxDfnyhQ==/split_lib_slice_8_apk.apk!/lib/arm64-v8a, /data/app/com.pethoalpar.myapplication-xdmsHX5km2PWImYxDfnyhQ==/split_lib_slice_9_apk.apk!/lib/arm64-v8a, /system/lib64, /system/vendor/lib64]]] couldn't find "libopencv_java3.so"
05-27 17:15:26.776 411-411/com.pethoalpar.myapplication W/System.err:     at java.lang.Runtime.loadLibrary0(Runtime.java:1011)
        at java.lang.System.loadLibrary(System.java:1657)
        at org.opencv.android.StaticHelper.loadLibrary(StaticHelper.java:64)
        at org.opencv.android.StaticHelper.initOpenCVLibs(StaticHelper.java:95)
        at org.opencv.android.StaticHelper.initOpenCV(StaticHelper.java:39)
        at org.opencv.android.OpenCVLoader.initDebug(OpenCVLoader.java:91)
        at com.pethoalpar.myapplication.MainActivity.onResume(MainActivity.java:80)
        at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1361)
        at android.app.Activity.performResume(Activity.java:7344)
        at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3763)
        at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3828)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3036)
        at android.app.ActivityThread.-wrap11(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696)
        at android.os.Handler.dispatchMessage(Handler.java:105)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6938)
05-27 17:15:26.777 411-411/com.pethoalpar.myapplication W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
05-27 17:15:26.777 411-411/com.pethoalpar.myapplication D/OpenCV/StaticHelper: First attempt to load libs fails
05-27 17:15:26.777 411-411/com.pethoalpar.myapplication D/MainActivity: OpenCv problem
05-27 17:15:26.790 411-416/com.pethoalpar.myapplication I/zygote64: Do partial code cache collection, code=61KB, data=37KB
    After code cache collection, code=61KB, data=37KB
    Increasing code cache capacity to 256KB
05-27 17:15:26.797 411-436/com.pethoalpar.myapplication D/OpenGLRenderer: HWUI GL Pipeline
05-27 17:15:26.802 411-411/com.pethoalpar.myapplication D/ViewRootImpl@bd62c20[MainActivity]: setView = DecorView@c62b9d9[MainActivity] TM=true MM=false
05-27 17:15:26.804 411-411/com.pethoalpar.myapplication D/OpenCVManager/Helper: Service connection created
05-27 17:15:26.807 411-411/com.pethoalpar.myapplication D/OpenCVManager/Helper: Trying to get library path
    Trying to get library list
    Library list: "libopencv_java3.so"
    First attempt to load libs
    Trying to init OpenCV libs
    Trying to load libs by dependency list
    Trying to load library /data/app/org.opencv.engine-1/lib/arm64/libopencv_java3.so
05-27 17:15:26.814 411-411/com.pethoalpar.myapplication D/OpenCVManager/Helper: OpenCV libs init was ok!
    First attempt to load libs is OK
05-27 17:15:26.819 411-411/com.pethoalpar.myapplication I/OpenCVManager/Helper: General configuration for OpenCV 3.3.1 =====================================
      Version control:               3.3.1
05-27 17:15:26.820 411-411/com.pethoalpar.myapplication I/OpenCVManager/Helper:   Platform:
        Timestamp:                   2017-10-24T14:00:34Z
        Host:                        Linux 4.8.0-58-generic x86_64
        Target:                      Linux 1 aarch64
        CMake:                       2.8.12.2
        CMake generator:             Ninja
        CMake build tool:            /usr/bin/ninja
        Configuration:               Release
      CPU/HW features:
        Baseline:                    NEON
          requested:                 NEON FP16
          required:                  NEON
          disabled:                  VFPV3
      C/C++:
        Built as dynamic libs?:      NO
        C++ Compiler:                /usr/bin/ccache /opt/android/android-ndk-r10e/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-g++ (ver 4.9)
        C++ flags (Release):         -fexceptions -frtti -Wno-psabi --sysroot=/opt/android/android-ndk-r10e/platforms/android-21/arch-arm64 -funwind-tables -fsigned-char -no-canonical-prefixes -fdata-sections -ffunction-sections -Wa,--noexecstack    -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -fdiagnostics-show-option -fomit-frame-pointer   -fvisibility=hidden -fvisibility-inlines-hidden -fomit-frame-pointer -fstrict-aliasing -funswitch-loops -finline-limit=300 -O3 -DNDEBUG  -DNDEBUG
        C++ flags (Debug):           -fexceptions -frtti -Wno-psabi --sysroot=/opt/android/android-ndk-r10e/platforms/android-21/arch-arm64 -funwind-tables -fsigned-char -no-canonical-prefixes -fdata-sections -ffunction-sections -Wa,--noexecstack    -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -fdiagnostics-show-option -fomit-frame-pointer   -fvisibility=hidden -fvisibility-inlines-hidden -fno-omit-frame-pointer -fno-strict-aliasing -O0 -g -DDEBUG -D_DEBUG  -DDEBUG -D_DEBUG
        C Compiler:                  /usr/bin/ccache /opt/android/android-ndk-r10e/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-gcc
        C flags (Release):           -fexceptions -Wno-psabi --sysroot=/opt/android/android-ndk-r10e/platforms/android-21/arch-arm64 -funwind-tables -fsigned-char -no-canonical-prefixes -fdata-sections -ffunction-sections -Wa,--noexecstack    -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-narrowing -Wno-comment -fdiagnostics-show-option -fomit-frame-pointer   -fvisibility=hidden -fomit-frame-pointer -fstrict-aliasing -funswitch-loops -finline-limit=300 -O3 -DNDEBUG  -DNDEBUG
        C flags (Debug):             -fexceptions -Wno-psabi --sysroot=/opt/android/android-ndk-r10e/platforms/android-21/arch-arm64 -funwind-tables -fsigned-char -no-canonical-prefixes -fdata-sections -ffunction-sections -Wa,--noexecstack    -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-narrowing -Wno-comment -fdiagnostics-show-option -fomit-frame-pointer   -fvisibility=hidden -fno-omit-frame-pointer -fno-strict-aliasing -O0 -g -DDEBUG -D_DEBUG  -DDEBUG -D_DEBUG
        Linker flags (Release):      -Wl,--no-undefined -Wl,--gc-sections -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now 
        Linker flags (Debug):        -Wl,--no-undefined -Wl,--gc-sections -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now 
        ccache:                      YES
        Precompiled headers:         NO
        Extra dependencies:          z dl m log
        3rdparty dependencies:       libcpufeatures libprotobuf libjpeg libwebp libpng libtiff libjasper IlmImf tegra_hal tbb
      OpenCV modules:
        To be built:                 core flann imgproc ml objdetect photo video dnn imgcodecs shape videoio highgui superres features2d calib3d java stitching videostab
        Disabled:                    js world
        Disabled by dependency:      -
        Unavailable:                 cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev python2 python3 ts viz
      Android: 
        Android ABI:                 arm64-v8a
        STL type:                    gnustl_static
        Native API level:            android-21
        SDK target:                  android-21
        Android NDK:                 /opt/android/android-ndk-r10e (toolchain: aarch64-linux-android-4.9)
        android tool:                /opt/android/android-sdk-java7/tools/android (Android SDK Tools, revision 25.2.2.)
        Google Play manager:         NO
        Android examples:            YES
      GUI: 
        GTK+:                        NO
        GThread :                    NO
        GtkGlExt:                    NO
        OpenGL support:              NO
        VTK support:                 NO
      Media I/O: 
        ZLib:                        z (ver 1.2.3)
        JPEG:                        build (ver 90)
        WEBP:                        build (ver encoder: 0x020e)
        PNG:                         build (ver 1.6.24)
        TIFF:                        build (ver 42 - 4.0.2)
        JPEG 2000:                   build (ver 1.900.1)
        OpenEXR:                     build (ver 1.7.1)
        GDAL:                        NO
        GDCM:                        NO
      Video I/O:
      Parallel framework:            TBB (ver 2018.0 interface 10001)
      Trace:                         YES ()
      Other third-party libraries:
        Use Intel IPP:               NO
        Use Intel IPP IW:            NO
        Use Eigen:                   NO
        Use Cuda:                    NO
        Use OpenCL:                  NO
        Use OpenVX:                  NO
        Use custom HAL:              YES (carotene (ver 0.0.1))
      Python 2:
        Interpreter:                 /usr/bin/python2.7 (ver 2.7.6)
      Python 3:
        Interpreter:                 /usr/bin/python3.4 (ver 3.4.3)
      Python (for build):            /usr/bin/python2.7
      Java:
        ant:                         /usr/bin/ant (ver 1.9.3)
        Java wrappers:               YES
        Java tests:                  NO
      Matlab:                        NO
      Tests and samples:
        Tests:                       NO
        Performance tests:           NO
        C/C++ Examples:              NO
      Install path:                  /build/master_pack-android/build/o4a/install
      cvconfig.h is in:              /build/master_pack-android/build/o4a
    -----------------------------------------------------------------
05-27 17:15:26.821 411-411/com.pethoalpar.myapplication D/OpenCVManager/Helper: Init finished with status 0
    Unbind from service
05-27 17:15:26.823 411-411/com.pethoalpar.myapplication D/OpenCVManager/Helper: Calling using callback
05-27 17:15:26.834 411-411/com.pethoalpar.myapplication D/ViewRootImpl@bd62c20[MainActivity]: dispatchAttachedToWindow
05-27 17:15:26.849 411-411/com.pethoalpar.myapplication V/Surface: sf_framedrop debug : 0x4f4c, game : false, logging : 0
05-27 17:15:26.850 411-411/com.pethoalpar.myapplication D/ViewRootImpl@bd62c20[MainActivity]: Relayout returned: old=[0,0][0,0] new=[0,0][1440,2960] result=0x7 surface={valid=true 507596918784} changed=true
05-27 17:15:26.856 411-436/com.pethoalpar.myapplication I/OpenGLRenderer: Initialized EGL, version 1.4
05-27 17:15:26.856 411-436/com.pethoalpar.myapplication D/OpenGLRenderer: Swap behavior 2
05-27 17:15:26.858 411-436/com.pethoalpar.myapplication D/libGLESv1: STS_GLApi : DTS, ODTC are not allowed for Package : com.pethoalpar.myapplication
05-27 17:15:26.862 411-436/com.pethoalpar.myapplication D/mali_winsys: EGLint new_window_surface(egl_winsys_display *, void *, EGLSurface, EGLConfig, egl_winsys_surface **, egl_color_buffer_format *, EGLBoolean) returns 0x3000,  [1440x2960]-format:1
05-27 17:15:26.862 411-436/com.pethoalpar.myapplication D/OpenGLRenderer: eglCreateWindowSurface = 0x7640e13e50
05-27 17:15:26.922 411-411/com.pethoalpar.myapplication D/ViewRootImpl@bd62c20[MainActivity]: MSG_RESIZED_REPORT: frame=Rect(0, 0 - 1440, 2960) ci=Rect(0, 96 - 0, 192) vi=Rect(0, 96 - 0, 192) or=1
    MSG_WINDOW_FOCUS_CHANGED 1
05-27 17:15:26.926 411-411/com.pethoalpar.myapplication V/InputMethodManager: Starting input: tba=android.view.inputmethod.EditorInfo@9eee7aa nm : com.pethoalpar.myapplication ic=null
05-27 17:15:26.926 411-411/com.pethoalpar.myapplication I/InputMethodManager: startInputInner - mService.startInputOrWindowGainedFocus
05-27 17:15:26.944 411-411/com.pethoalpar.myapplication V/InputMethodManager: Starting input: tba=android.view.inputmethod.EditorInfo@cca9f9b nm : com.pethoalpar.myapplication ic=null
05-27 17:15:30.789 411-411/com.pethoalpar.myapplication D/ViewRootImpl@bd62c20[MainActivity]: ViewPostIme pointer 0
05-27 17:15:30.837 411-411/com.pethoalpar.myapplication D/ViewRootImpl@bd62c20[MainActivity]: ViewPostIme pointer 1
05-27 17:15:30.852 411-411/com.pethoalpar.myapplication E/MainActivity: file:///storage/emulated/0/Tess/imgs/ocr.jpg exposed beyond app through ClipData.Item.getUri()
05-27 17:15:31.221 411-411/com.pethoalpar.myapplication D/ViewRootImpl@bd62c20[MainActivity]: ViewPostIme pointer 0
05-27 17:15:31.271 411-411/com.pethoalpar.myapplication D/ViewRootImpl@bd62c20[MainActivity]: ViewPostIme pointer 1
05-27 17:15:31.282 411-411/com.pethoalpar.myapplication E/MainActivity: file:///storage/emulated/0/Tess/imgs/ocr.jpg exposed beyond app through ClipData.Item.getUri()
05-27 17:15:31.535 411-411/com.pethoalpar.myapplication D/ViewRootImpl@bd62c20[MainActivity]: ViewPostIme pointer 0
05-27 17:15:31.627 411-411/com.pethoalpar.myapplication D/ViewRootImpl@bd62c20[MainActivity]: ViewPostIme pointer 1
05-27 17:15:31.632 411-411/com.pethoalpar.myapplication E/MainActivity: file:///storage/emulated/0/Tess/imgs/ocr.jpg exposed beyond app through ClipData.Item.getUri()
4

0 回答 0