Android上的OpenCV链接错误

时间:2018-06-14 18:33:25

标签: android opencv

我想让OpenCV在Android上运行。我已经遵循了几个教程,到目前为止没有成功。一种方法是OpenCVManager,但是当我尝试样本时它们不起作用。

我现在尝试的方法是使用NDK并通过CMakeAndroid.mk添加OpenCV。到目前为止没有成功。一般来说,这是开始使用OpenCV和Android的最佳方法吗?

我尝试创建一个空矩阵cv::Mat tmp,但我总是遇到链接错误。

../../../../src/main/jniLibs/jni/include/opencv2/core/mat.inl.hpp:704: error: undefined reference to 'cv::fastFree(void*)'

我尝试添加不同的调用,例如-lopencv_core等等。我不确定的一件事实际上是如何链接。有些静态库包含libopencv_core.so等等。但是,jni/libs/仅包含libopencv_java3.so。究竟应该链接哪些库以及如何链接?

CMakeLists.txt

cmake_minimum_required(VERSION 3.4.1)

include_directories(src/main/jniLibs/jni/include)
add_library( lib_opencv SHARED IMPORTED )
set_target_properties(lib_opencv PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/src/main/jniLibs/libs/${ANDROID_ABI}/libopencv_java3.so)
add_library( native-lib SHARED src/main/cpp/native-lib.cpp )


find_library( # Sets the name of the path variable.
              log-lib

              # Specifies the name of the NDK library that
              # you want CMake to locate.
              log )

target_link_libraries( # Specifies the target library.
                       native-lib

                       # Links the target library to the log library
                       # included in the NDK.
                       ${log-lib} )

Android.mk

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

OPENCV_LIB_TYPE:=SHARED
OPENCV_CAMERA_MODULES:=on
OPENCV_INSTALL_MODULES:=on

include {/home/myname/Code/Libraries/Android/OpenCV-android-sdk/sdk/native/jni/OpenCV.mk}

LOCAL_SRC_FILES  += $(LOCAL_PATH)/native-lib.cpp
LOCAL_C_INCLUDES += {/home/myname/Code/Libraries/Android/OpenCV-android-sdk/sdk/native/jni/include}
include $(PREBUILT_STATIC_LIBRARY)
LOCAL_LDLIBS     += -llog -ldl
LOCAL_CFLAGS    += -DOPENCV_OLDER_VISION

LOCAL_CPP_FEATURES += exceptions (Recommended)
LOCAL_CPPFLAGS += -fexceptions


LOCAL_MODULE     := native-lib

include $(BUILD_SHARED_LIBRARY)

1 个答案:

答案 0 :(得分:0)

我按照这个例子进行了OpenCV编译。 https://github.com/sjfricke/OpenCV-NDK

虽然FaceDetection崩溃了,但这可能是因为没有正确加载相关的xml - 文件。