简体   繁体   English

Android上的OpenCV链接错误

[英]OpenCV linking error on android

I am trying to get OpenCV to work on Android. 我正在尝试让OpenCV在Android上运行。 I have followed several tutorials and no success so far. 我遵循了一些教程,到目前为止没有成功。 One approach is OpenCVManager , but when I try the samples they do not work. 一种方法是OpenCVManager ,但是当我尝试示例时它们不起作用。

The approach I am trying now is to use NDK and add OpenCV through CMake and Android.mk . 我现在尝试的方法是使用NDK并通过CMakeAndroid.mk添加OpenCV。 No success so far. 到目前为止没有成功。 In general, which is the best approach to get started with OpenCV and Android? 通常,哪种是开始使用OpenCV和Android的最佳方法?

I try to just create an empty matrix cv::Mat tmp , but I always get a linking error. 我尝试只创建一个空矩阵cv::Mat tmp ,但是我总是遇到链接错误。

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

I have tried adding different calls like -lopencv_core and so forth. 我尝试添加不同的调用,例如-lopencv_core等。 One thing I am not sure about is actually how to link. 我不确定的一件事实际上是如何链接。 There are the static libs that contain libopencv_core.so and so forth. 有包含libopencv_core.so等的静态库。 However, jni/libs/ only contains libopencv_java3.so . 但是, jni/libs/仅包含libopencv_java3.so Exactly which libraries am I supposed to link against and how? 我应该链接哪些库,以及如何链接?

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)

I followed this example and made OpenCV compile. 我遵循了这个示例,并进行了OpenCV编译。 https://github.com/sjfricke/OpenCV-NDK https://github.com/sjfricke/OpenCV-NDK

Although FaceDetection crashes, but that is probably because the relevant xml -files are not loaded correctly. 尽管FaceDetection崩溃,但这可能是因为相关xml文件未正确加载。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM