OpenCV - undefined reference to 'cv::CascadeClassifier::detectMultiScale() after NDK update

后端 未结 5 1323

Yesterday I updated my Android Studio included NDK to version 17.0.4754217and since then I can\'t run my app anymore. When I tried to rerun the code after the u

5条回答
  •  情书的邮戳
    2021-01-06 07:30

    I solved this problem by using mix with this OpenCV + contrib lib (opencv4_1_0_contrib) and official Java OpenCV classes (4.3). Successfully run official OpenCV FaceDetection example on Android 9.


    Some usefull code:

    App level build.gradle:

    android{defaultConfig{
    //...
    externalNativeBuild {
                cmake {
                    cppFlags "-frtti -fexceptions"
                    abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
                    //I import OpenCV as module and provide it path to CMake
                    arguments "-DOpenCV_DIR=/" + rootProject.projectDir.path + "/sdk/native"
                 }
            }
    }}
    
    externalNativeBuild {
            cmake {
                path "src/main/cpp/CMakeLists.txt"
                version "3.10.2"
            }
        }
    

    My CMakeLists.txt:

    # Sets the minimum version of CMake required to build the native library.
    cmake_minimum_required(VERSION 3.4.1)
    
    #Add OpenCV 4 lib
    include_directories(${OpenCV_DIR}/jni/include) #Path from gradle to OpenCV Cmake
    add_library( lib_opencv SHARED IMPORTED )
    set_target_properties(lib_opencv PROPERTIES IMPORTED_LOCATION ${OpenCV_DIR}/libs/${ANDROID_ABI}/libopencv_java4.so)
    
    #Add Your Native Lib
    add_library(native-lib SHARED native-lib.cpp)
    add_library(detection_based_tracker SHARED detectionbasedtracker_jni.cpp)
    
    #Add&Link Android Native Log lib with others libs
    find_library(log-lib log)
    target_link_libraries(detection_based_tracker lib_opencv ${log-lib})
    

    NDK version was 21.0.611669. Also I don't use arguments for CMake like -DANDROID_STL=gnustl_static.

提交回复
热议问题