添加的tesseract和OpenCV到Android.mk(Android的工作室) [英] Adding Tesseract and Opencv to Android.mk (Android Studio)

查看:642
本文介绍了添加的tesseract和OpenCV到Android.mk(Android的工作室)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我也跟着从<一的说明href=\"http://hujiaweibujidao.github.io/blog/2014/10/22/android-ndk-and-opencv-development-with-android-studio/\"相对=nofollow>这里并添加OpenCV的成功。但我一直在努力的tesseract现在添加到Android.mk为好,几天了,还没有能够做到这一点。

我有一个的 android.cpp 的使用的tesseract所以我要包括我Android.mk的依赖。我发现<一个href=\"http://stackoverflow.com/questions/23965907/how-to-use-android-tesseract-android-mk-files-in-my-android-mk\">this帖子这几乎确切的问题,他解决了进口的 libtess.so 的和的 liblept.so 的文件到Android.mk,但并没有解释如何做到这一点,所以我看了一下,发现<一个href=\"http://stackoverflow.com/questions/9870435/how-can-i-link-$p$pbuilt-shared-library-to-android-ndk-project/9922835#9922835\">this帖子显示如何链接prebuilt库。因此,基于我尝试这样Android.mk:

  LOCAL_PATH:= $(叫我-DIR)包括$(CLEAR_VARS)
LOCAL_MODULE:= liblept
LOCAL_SRC_FILES:= ../libs/$(TARGET_ARCH_ABI)/liblept.so
LOCAL_EXPORT_C_INCLUDES:= $(LOCAL_PATH)/../../../../苔丝个/ JNI
包括$(preBUILT_SHARED_LIBRARY)包括$(CLEAR_VARS)
LOCAL_MODULE:= libtess
LOCAL_SRC_FILES:= ../libs/$(TARGET_ARCH_ABI)/libtess.so
LOCAL_EXPORT_C_INCLUDES:= $(LOCAL_PATH)/../../../../苔丝个/ JNI
包括$(preBUILT_SHARED_LIBRARY)包括$(CLEAR_VARS)
OPENCV_PACKAGE_DIR:= /Users/danielsierraf/Documents/OpenCV-2.4.10-android-sdk/sdk
OPENCV_CAMERA_MODULES:=关闭
包括$(OPENCV_PACKAGE_DIR)/native/jni/OpenCV.mkLOCAL_MODULE:= run_detection
LOCAL_SHARED_LIBRARIES:= libtess
LOCAL_SRC_FILES:= text_detect.cpp android.cpp
LOCAL_LDLIBS + = -landroid -llog -ldl包括$(BUILD_SHARED_LIBRARY)

和得到这个输出:

  [armeabi-V7A] prebuilt:liblept.so&LT; =的src / main / JNI /../库/ armeabi-V7A /
[armeabi-V7A]安装:liblept.so =&GT;在src / main / jniLibs / armeabi-V7A / liblept.so
[armeabi-V7A] ++编译大拇指:run_detection&LT; = text_detect.cpp
在从文件的src /主要包括/ JNI / text_detect.h:4:0,
                 从的src / main / JNI / text_detect.cpp:10:
在src / main / JNI /../../../../苔丝个/ JNI / com_google code_tesseract_android / src目录/ API / baseapi.h:32:22:致命错误:platform.h:无这样的文件或目录
 #包括platform.h
                      ^
编译终止。

所以我想没有正确连接libtess,如果你仔细观察,它不会永远安装libtess.so,它看起来像它安装的 liblept.so 的,然后跳转到的 text_detect.cpp 的,忽略这一部分:

 包含$(CLEAR_VARS)
LOCAL_MODULE:= libtess
LOCAL_SRC_FILES:= ../libs/$(TARGET_ARCH_ABI)/libtess.so
LOCAL_EXPORT_C_INCLUDES:= $(LOCAL_PATH)/../../../../苔丝个/ JNI
包括$(preBUILT_SHARED_LIBRARY)

于是,我就迫使它安装的 liblept 的和的 libtess 的完全将它放在不同的文件然后再继续。所以,我把文件的最后部分在不同的Andr​​oid.mk在另一个文件夹,并试图的包括$(调用所有子目录,makefile文件)的,然后将其安装的 libtess 的和 liblept 的彻底,但忽略的呼吁所有子目录,makefile文件的。

新的JNI的文件夹结构:

  Android.mk
Application.mk
text_detect /
     Android.mk
     android.cpp
     text_detect.cpp
     text_detect.h

Android.mk

  LOCAL_PATH:= $(叫我-DIR)包括$(CLEAR_VARS)
LOCAL_MODULE:= liblept
LOCAL_SRC_FILES:= ../libs/$(TARGET_ARCH_ABI)/liblept.so
LOCAL_EXPORT_C_INCLUDES:= $(LOCAL_PATH)/../../../../苔丝个/ JNI
包括$(preBUILT_SHARED_LIBRARY)包括$(CLEAR_VARS)
LOCAL_MODULE:= libtess
LOCAL_SRC_FILES:= ../libs/$(TARGET_ARCH_ABI)/libtess.so
LOCAL_EXPORT_C_INCLUDES:= $(LOCAL_PATH)/../../../../苔丝个/ JNI
包括$(preBUILT_SHARED_LIBRARY)包括$(调用所有子目录,makefile文件)

textdetect / Android.mk

  LOCAL_PATH:= $(叫我-DIR)包括$(CLEAR_VARS)OPENCV_PACKAGE_DIR:= /Users/danielsierraf/Documents/OpenCV-2.4.10-android-sdk/sdk
OPENCV_CAMERA_MODULES:=关闭
包括$(OPENCV_PACKAGE_DIR)/native/jni/OpenCV.mkLOCAL_MODULE:= run_detection
LOCAL_SHARED_LIBRARIES:= libtess
LOCAL_SRC_FILES:= text_detect.cpp android.cpp
LOCAL_LDLIBS + = -landroid -llog -ldl包括$(BUILD_SHARED_LIBRARY)

这是输出:

  [armeabi-V7A] prebuilt:liblept.so&LT; =的src / main / JNI /../库/ armeabi-V7A /
[armeabi-V7A]安装:liblept.so =&GT;在src / main / jniLibs / armeabi-V7A / liblept.so
[armeabi-V7A] prebuilt:libtess.so&LT; =的src / main / JNI /../库/ armeabi-V7A /
[armeabi-V7A]安装:libtess.so =&GT;在src / main / jniLibs / armeabi-V7A / libtess.so
[armeabi] prebuilt:liblept.so&LT; =的src / main / JNI /../库/ armeabi /
[armeabi]安装:liblept.so =&GT;在src / main / jniLibs / armeabi / liblept.so
[armeabi] prebuilt:libtess.so&LT; =的src / main / JNI /../库/ armeabi /
[armeabi]安装:libtess.so =&GT;在src / main / jniLibs / armeabi / libtess.so
[MIPS] prebuilt:liblept.so&LT; =的src / main / JNI /../库/ MIPS /
[MIPS]安装:liblept.so =&GT;在src / main / jniLibs / MIPS / liblept.so
[MIPS] prebuilt:libtess.so&LT; =的src / main / JNI /../库/ MIPS /
[MIPS]安装:libtess.so =&GT;在src / main / jniLibs / MIPS / libtess.so
[86] prebuilt:liblept.so&LT; =的src / main / JNI /../库/ 86 /
[86]安装:liblept.so =&GT;在src / main / jniLibs / 86 / liblept.so
[86] prebuilt:libtess.so&LT; =的src / main / JNI /../库/ 86 /
[86]安装:libtess.so =&GT;在src / main / jniLibs / 86 / libtess.so

当你看到它安装了从第一Android.mk完美,但它从来没有运行textdetect / Android.mk

所以,我什么,我做错了吗?我怎样才能实现这个任务似乎很简单?是否有更简单的方法?

编辑:

在@ ph0b响应我回到我的第一个设置并添加相同 LOCAL_EXPORT_C_INCLUDES 的<一个href=\"https://github.com/rmtheis/tess-two/blob/master/tess-two/jni/com_google$c$c_tesseract_android/Android.mk#L33\"相对=nofollow>原来的Makefile (一对夫妇的变化是适应我的路径),并且解决它。它找不到 platform.h ,因为它不知道去哪里找。

现在,当我做了这个变化我有一个不同的误差没有这样的文件或目录的#includecom_google code_tesseract_android / src目录/ API / baseapi.h我以为这是因为它没有编译之前 run_detection 的tesseract依赖于它。嗯,这是没有问题的,但它仍然编译 run_detection 的tesseract之前但是这不是问题,这是非常简单的,我觉得这样愚蠢花了这么多时间在这错误。问题是它没有找到 com_google code_tesseract_android / src目录/ API / baseapi.h ,因为我没有为这条道路不是,所以我复制 com_google code_tesseract_android com_google code_leptonica_android 来自的苔丝二,并添加 $(LOCAL_PATH) LOCAL_EXPORT_C_INCLUDES 。这是我的最终解决方案:

JNI文件夹结构:

  Android.mk
Application.mk
text_detect.cpp
android.cpp
text_detect.h
com_google code_leptonica_android
com_google code_tesseract_android

Android.mk

  LOCAL_PATH:= $(叫我-DIR)#leptonica
LEPTONICA_LOCAL:= $(LOCAL_PATH)/ com_google code_leptonica_android
LEPTONICA_PATH:= $(LOCAL_PATH)/ src目录包括$(CLEAR_VARS)LOCAL_MODULE:= liblept
LOCAL_SRC_FILES:= ../libs/$(TARGET_ARCH_ABI)/liblept.so
LOCAL_EXPORT_C_INCLUDES:= \\
  $(LEPTONICA_LOCAL)\\
  $(LEPTONICA_PATH)/ src目录包括$(preBUILT_SHARED_LIBRARY)#tesseract
TESSERACT_LOCAL:= $(LOCAL_PATH)/ com_google code_tesseract_android
TESSERACT_PATH:= $(TESSERACT_LOCAL)/ src目录包括$(CLEAR_VARS)LOCAL_MODULE:= libtess
LOCAL_SRC_FILES:= ../libs/$(TARGET_ARCH_ABI)/libtess.so
LOCAL_EXPORT_C_INCLUDES:= \\
  $(LOCAL_PATH)\\
  $(TESSERACT_PATH)/ API \\
  $(TESSERACT_PATH)/ ccmain \\
  $(TESSERACT_PATH)/ ccstruct \\
  $(TESSERACT_PATH)/ ccutil \\
  $(TESSERACT_PATH)/分类\\
  $(TESSERACT_PATH)/立方\\
  $(TESSERACT_PATH)/ cutil \\
  $(TESSERACT_PATH)/字典\\
  $(TESSERACT_PATH)/ OpenCL的\\
  $(TESSERACT_PATH)/ neural_networks /运行\\
  $(TESSERACT_PATH)/ textord \\
  $(TESSERACT_PATH)/观众\\
  $(TESSERACT_PATH)/ wordrec \\
  $(LEPTONICA_PATH)/ src目录\\
  $(TESSERACT_LOCAL)
LOCAL_SHARED_LIBRARIES:= liblept包括$(preBUILT_SHARED_LIBRARY)#opencv
包括$(CLEAR_VARS)
OPENCV_PACKAGE_DIR:= /Users/danielsierraf/Documents/OpenCV-2.4.10-android-sdk/sdk
OPENCV_CAMERA_MODULES:=关闭
包括$(OPENCV_PACKAGE_DIR)/native/jni/OpenCV.mkLOCAL_MODULE:= run_detection
LOCAL_SRC_FILES:= text_detect.cpp android.cpp
LOCAL_LDLIBS + = -landroid -llog -ldl
LOCAL_SHARED_LIBRARIES + = libtess liblept包括$(BUILD_SHARED_LIBRARY)


解决方案

您最新的安装是在一个奇怪的方式失败,NDK的构建至少应该尝试编译你的模块。也许有在中的错误全子目录-的makefile 当有之前定义的NDK模块,并且它没有找到你的模块的Andr​​oid.mk。您可以尝试只具有包含$(调用所有子目录,makefile文件)您的顶级Android.mk内。

无论如何,我认为你应该直接在JNI根文件夹回到你的第一个设置,用你的模块。那么,你的主要问题是正确的声明包括路径。苔丝个/ JNI不包含任何头?他们在苔丝个/ JNI / com_google code _ * _安卓/ src目录/ * 。这意味着你需要在你的模块声明列出这些,通过给所有的绝对路径 LOCAL_EXPORT_C_INCLUDES 变量(如从原来的Makefile:<一href=\"https://github.com/rmtheis/tess-two/blob/master/tess-two/jni/com_google$c$c_tesseract_android/Android.mk#L33\" rel=\"nofollow\">https://github.com/rmtheis/tess-two/blob/master/tess-two/jni/com_google$c$c_tesseract_android/Android.mk#L33)

您还需要添加liblept依赖于libtess: LOCAL_SHARED_LIBRARIES:= liblept libtess库声明中

如果仍然失败,也有另一种可能性:不是使用生成的.so文件重新定义libtess和liblept模块,您可以直接包含苔丝个/ JNI / Android.mk 并使用相同的Application.mk比苔丝二(复印件苔丝个/ JNI / Application.mk)。它将已经正确定义libtess和liblept模块。

I followed the instructions from here and added OpenCV successfully. But I've been trying to add tesseract to the Android.mk as well, for a few days now, and haven't been able to do it.

I have an android.cpp that uses tesseract so I have to include the dependency in my Android.mk . I found this post that had almost the exact problem and he solved it importing libtess.so and liblept.so files into Android.mk, but didn't explain how to do that, so I looked and found this post that shows how to link prebuilt libraries. So based on that I tried this Android.mk:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := liblept
LOCAL_SRC_FILES := ../libs/$(TARGET_ARCH_ABI)/liblept.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../../../../tess-two/jni
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libtess
LOCAL_SRC_FILES := ../libs/$(TARGET_ARCH_ABI)/libtess.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../../../../tess-two/jni
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
OPENCV_PACKAGE_DIR:= /Users/danielsierraf/Documents/OpenCV-2.4.10-android-sdk/sdk
OPENCV_CAMERA_MODULES := off
include $(OPENCV_PACKAGE_DIR)/native/jni/OpenCV.mk

LOCAL_MODULE    := run_detection
LOCAL_SHARED_LIBRARIES := libtess
LOCAL_SRC_FILES := text_detect.cpp android.cpp
LOCAL_LDLIBS    += -landroid -llog -ldl

include $(BUILD_SHARED_LIBRARY)

And got this output:

[armeabi-v7a] Prebuilt       : liblept.so <= src/main/jni/../libs/armeabi-v7a/
[armeabi-v7a] Install        : liblept.so => src/main/jniLibs/armeabi-v7a/liblept.so
[armeabi-v7a] Compile++ thumb: run_detection <= text_detect.cpp
In file included from src/main/jni/text_detect.h:4:0,
                 from src/main/jni/text_detect.cpp:10:
src/main/jni/../../../../tess-two/jni/com_googlecode_tesseract_android/src/api/baseapi.h:32:22: fatal error: platform.h: No such file or directory
 #include "platform.h"
                      ^
compilation terminated.

So I guess is not linking libtess correctly, and if you look closely, it doesn't ever install libtess.so, it looks like it installs liblept.so, and then jumps to text_detect.cpp, ignoring this part:

include $(CLEAR_VARS)
LOCAL_MODULE := libtess
LOCAL_SRC_FILES := ../libs/$(TARGET_ARCH_ABI)/libtess.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../../../../tess-two/jni
include $(PREBUILT_SHARED_LIBRARY)

So I tried to force it to install liblept and libtess completely before proceeding by putting it in different files. So I put the last part of the file in a different Android.mk in another folder and tried include $(call all-subdir-makefiles), and then it installs libtess and liblept completely, but ignores the call all-subdir-makefiles.

new jni folder structure:

Android.mk
Application.mk
text_detect/
     Android.mk
     android.cpp
     text_detect.cpp
     text_detect.h

Android.mk

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := liblept
LOCAL_SRC_FILES := ../libs/$(TARGET_ARCH_ABI)/liblept.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../../../../tess-two/jni
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libtess
LOCAL_SRC_FILES := ../libs/$(TARGET_ARCH_ABI)/libtess.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../../../../tess-two/jni
include $(PREBUILT_SHARED_LIBRARY)

include $(call all-subdir-makefiles)

textdetect/Android.mk

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

OPENCV_PACKAGE_DIR:= /Users/danielsierraf/Documents/OpenCV-2.4.10-android-sdk/sdk
OPENCV_CAMERA_MODULES := off
include $(OPENCV_PACKAGE_DIR)/native/jni/OpenCV.mk

LOCAL_MODULE    := run_detection
LOCAL_SHARED_LIBRARIES := libtess
LOCAL_SRC_FILES := text_detect.cpp android.cpp
LOCAL_LDLIBS    += -landroid -llog -ldl

include $(BUILD_SHARED_LIBRARY)

And this is the output:

[armeabi-v7a] Prebuilt       : liblept.so <= src/main/jni/../libs/armeabi-v7a/
[armeabi-v7a] Install        : liblept.so => src/main/jniLibs/armeabi-v7a/liblept.so
[armeabi-v7a] Prebuilt       : libtess.so <= src/main/jni/../libs/armeabi-v7a/
[armeabi-v7a] Install        : libtess.so => src/main/jniLibs/armeabi-v7a/libtess.so
[armeabi] Prebuilt       : liblept.so <= src/main/jni/../libs/armeabi/
[armeabi] Install        : liblept.so => src/main/jniLibs/armeabi/liblept.so
[armeabi] Prebuilt       : libtess.so <= src/main/jni/../libs/armeabi/
[armeabi] Install        : libtess.so => src/main/jniLibs/armeabi/libtess.so
[mips] Prebuilt       : liblept.so <= src/main/jni/../libs/mips/
[mips] Install        : liblept.so => src/main/jniLibs/mips/liblept.so
[mips] Prebuilt       : libtess.so <= src/main/jni/../libs/mips/
[mips] Install        : libtess.so => src/main/jniLibs/mips/libtess.so
[x86] Prebuilt       : liblept.so <= src/main/jni/../libs/x86/
[x86] Install        : liblept.so => src/main/jniLibs/x86/liblept.so
[x86] Prebuilt       : libtess.so <= src/main/jni/../libs/x86/
[x86] Install        : libtess.so => src/main/jniLibs/x86/libtess.so

As you see it installs everything from the first Android.mk perfectly, but it never runs textdetect/Android.mk

So, what I'm I doing wrong? How can I achieve this task that seems so simple? Is there an easier way?

EDIT:

After @ph0b response I went back to my first setup and added the same LOCAL_EXPORT_C_INCLUDES as the original Makefiles (with a couple of variations adapting it to my paths), and that solved it. It couldn't find platform.h because it didn't know where to look for it.

Now, after I did this change I had a different error No such file or directory #include "com_googlecode_tesseract_android/src/api/baseapi.h" and I thought this was because it didn't compile tesseract before run_detection that depends on it. Well that wasn't the problem, it still compiles run_detection before tesseract but that wasn't the issue, it was so much simpler and I feel so stupid for having spent so much time on this error. The problem was it didn't find com_googlecode_tesseract_android/src/api/baseapi.h because I didn't provide the path for that either, so I copied com_googlecode_tesseract_android and com_googlecode_leptonica_android from tess-two and added $(LOCAL_PATH) to LOCAL_EXPORT_C_INCLUDES. This is my final solution:

jni folder structure:

Android.mk
Application.mk
text_detect.cpp
android.cpp
text_detect.h
com_googlecode_leptonica_android
com_googlecode_tesseract_android

Android.mk

LOCAL_PATH := $(call my-dir)

#leptonica
LEPTONICA_LOCAL := $(LOCAL_PATH)/com_googlecode_leptonica_android
LEPTONICA_PATH := $(LOCAL_PATH)/src

include $(CLEAR_VARS)

LOCAL_MODULE := liblept
LOCAL_SRC_FILES := ../libs/$(TARGET_ARCH_ABI)/liblept.so
LOCAL_EXPORT_C_INCLUDES := \
  $(LEPTONICA_LOCAL) \
  $(LEPTONICA_PATH)/src

include $(PREBUILT_SHARED_LIBRARY)

#tesseract
TESSERACT_LOCAL := $(LOCAL_PATH)/com_googlecode_tesseract_android
TESSERACT_PATH := $(TESSERACT_LOCAL)/src

include $(CLEAR_VARS)

LOCAL_MODULE := libtess
LOCAL_SRC_FILES := ../libs/$(TARGET_ARCH_ABI)/libtess.so
LOCAL_EXPORT_C_INCLUDES := \
  $(LOCAL_PATH) \
  $(TESSERACT_PATH)/api \
  $(TESSERACT_PATH)/ccmain \
  $(TESSERACT_PATH)/ccstruct \
  $(TESSERACT_PATH)/ccutil \
  $(TESSERACT_PATH)/classify \
  $(TESSERACT_PATH)/cube \
  $(TESSERACT_PATH)/cutil \
  $(TESSERACT_PATH)/dict \
  $(TESSERACT_PATH)/opencl \
  $(TESSERACT_PATH)/neural_networks/runtime \
  $(TESSERACT_PATH)/textord \
  $(TESSERACT_PATH)/viewer \
  $(TESSERACT_PATH)/wordrec \
  $(LEPTONICA_PATH)/src \
  $(TESSERACT_LOCAL)
LOCAL_SHARED_LIBRARIES := liblept

include $(PREBUILT_SHARED_LIBRARY)

#opencv
include $(CLEAR_VARS)
OPENCV_PACKAGE_DIR:= /Users/danielsierraf/Documents/OpenCV-2.4.10-android-sdk/sdk
OPENCV_CAMERA_MODULES := off
include $(OPENCV_PACKAGE_DIR)/native/jni/OpenCV.mk

LOCAL_MODULE    := run_detection
LOCAL_SRC_FILES := text_detect.cpp android.cpp
LOCAL_LDLIBS    += -landroid -llog -ldl
LOCAL_SHARED_LIBRARIES += libtess liblept

include $(BUILD_SHARED_LIBRARY)

解决方案

Your latest setup is failing in a weird way, ndk-build should at least try to compile your module. Maybe there is a bug in all-subdir-makefiles when there are ndk modules defined before it, and it doesn't find your module's Android.mk. You can try having only include $(call all-subdir-makefiles) inside your top level Android.mk.

Anyway, I think you should go back to your first setup, with your module directly in the jni root folder. Then, your main issue is the proper declaration of includes paths. tess-two/jni doesn't contain any headers ? They're in tess-two/jni/com_googlecode_*_android/src/*. That means you need to list these in your module declarations, by giving all the absolute paths to LOCAL_EXPORT_C_INCLUDES variables (like from the original Makefiles: https://github.com/rmtheis/tess-two/blob/master/tess-two/jni/com_googlecode_tesseract_android/Android.mk#L33)

You also need to add the dependency on liblept for libtess: LOCAL_SHARED_LIBRARIES := liblept inside libtess library declaration.

If it still fails, there is also another possibility: instead of redefining libtess and liblept modules using the generated .so files, you can directly include tess-two/jni/Android.mk and use the same Application.mk than tess-two (copy `tess-two/jni/Application.mk). It will already properly define libtess and liblept modules.

这篇关于添加的tesseract和OpenCV到Android.mk(Android的工作室)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆