我按照here的说明操作,并成功添加了OpenCV。但是我已经尝试将tesseract添加到Android.mk中,现在已经有几天了,并且无法做到。
我有一个使用tesseract的 android.cpp ,因此我必须在Android.mk中包含依赖项。我发现this post几乎确实存在问题,他解决了将 libtess.so 和 liblept.so 文件导入Android.mk的问题,但没有解释怎么做,所以我查看并找到了this post,它显示了如何链接预建的库。基于此,我尝试了这个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)
得到了这个输出:
[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.
所以我猜是没有正确链接libtess,如果仔细观察,它就不会安装libtess.so,看起来它安装 liblept.so ,然后跳转到 text_detect.cpp ,忽略此部分:
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)
因此我尝试强制它完全安装 liblept 和 libtess ,然后再将其放入不同的文件中。所以我将文件的最后一部分放在另一个文件夹中的另一个Android.mk中并尝试 include $(调用all-subdir-makefiles),然后安装 libtess 和 liblept 完全,但忽略调用all-subdir-makefiles 。
新的jni文件夹结构:
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)
这是输出:
[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
正如您所看到的,它完美地安装了第一个Android.mk中的所有内容,但它从未运行textdetect / Android.mk
那么,我做错了什么?我怎样才能实现这么简单的任务呢?有更简单的方法吗?
修改
在@ ph0b回复之后,我回到了我的第一个设置并添加了与original Makefiles相同的LOCAL_EXPORT_C_INCLUDES
(有几个变体使其适应我的路径),这解决了它。它找不到platform.h
,因为它不知道在哪里寻找它。
现在,在我做了这个更改之后,我遇到了一个不同的错误No such file or directory #include "com_googlecode_tesseract_android/src/api/baseapi.h"
,我认为这是因为它没有在依赖它的run_detection
之前编译tesseract。好吧,这不是问题,它仍然在tesseract之前编译run_detection
,但这不是问题,它是如此简单,我觉得因为花了这么多时间在这个错误上是如此愚蠢。问题是找不到com_googlecode_tesseract_android/src/api/baseapi.h
因为我没有提供相应的路径,所以我从tess-two复制了com_googlecode_tesseract_android
和com_googlecode_leptonica_android
并添加了{{1}到$(LOCAL_PATH)
。这是我的最终解决方案:
jni文件夹结构:
LOCAL_EXPORT_C_INCLUDES
Android.mk
Android.mk
Application.mk
text_detect.cpp
android.cpp
text_detect.h
com_googlecode_leptonica_android
com_googlecode_tesseract_android
答案 0 :(得分:1)
你的最新设置是以一种奇怪的方式失败,ndk-build至少应该尝试编译你的模块。可能在all-subdir-makefiles
之前有一个错误,如果在它之前定义了ndk模块,并且它找不到你的模块的Android.mk。您可以尝试在顶级Android.mk中仅使用include $(call all-subdir-makefiles)
。
无论如何,我认为您应该回到第一次设置,将模块直接放在jni根文件夹中。然后,您的主要问题是包含路径的正确声明。 tess-two / jni不包含任何标题?他们在tess-two/jni/com_googlecode_*_android/src/*
。这意味着您需要在模块声明中列出这些,通过提供LOCAL_EXPORT_C_INCLUDES
变量的所有绝对路径(例如来自原始Makefile:https://github.com/rmtheis/tess-two/blob/master/tess-two/jni/com_googlecode_tesseract_android/Android.mk#L33)
您还需要在libtess库声明中为libtess:LOCAL_SHARED_LIBRARIES := liblept
添加对liblept的依赖。
如果它仍然失败,还有另一种可能性:使用生成的.so文件而不是重新定义libtess和liblept模块,您可以直接包含tess-two/jni/Android.mk
并使用相同的Application.mk而不是tess-two(副本苔丝-2 / JNI / Application.mk)。它已经正确定义了libtess和liblept模块。