I'm trying to use opencv native library in an android studio project. I get an error for undefined reference for the function knnMatch.
I have added openCVLibrary to my project and had success to use other openCV features.
- Is there a specific why to use libopencv_features2d?
- What is to proper way to compile and link features2d?
UPDATE: Add my compiling files
My App build.gradle :
apply plugin: 'com.android.application'
//
android {
compileSdkVersion 27
buildToolsVersion '27.0.3'
//
defaultConfig {
minSdkVersion 21
targetSdkVersion 27
...
externalNativeBuild {
cmake {
arguments "-DANDROID_ARM_NEON=TRUE", "-DANDROID_TOOLCHAIN=clang" , "-DANDROID_STL=c++_static","-DCMAKE_BUILD_TYPE=Release", "-DANDROID_CPP_FEATURES=rtti exceptions"
cppFlags "-D__STDC_FORMAT_MACROS" , '-O3','-fopenmp','-fsigned-char', "-std=c++14", "-frtti", "-fexceptions", "-mfloat-abi=softfp", "-Wall"
}
ndk {
abiFilters 'arm64-v8a'
}
}
}
//
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
...
}
//
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
implementation project(':openCVLibrary340') //Module
}
My CMakeList.txt :
cmake_minimum_required(VERSION 3.4.1)
#
include_directories(/.../OpenCV-android-sdk/sdk/native/jni/include)
add_library( libopencv SHARED IMPORTED )
set_target_properties(libopencv PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/libopencv_java3.so)
#
FILE(GLOB CPP_SRC
"src/main/cpp/*.c"
"src/main/cpp/*.h"
"src/main/cpp/*.cpp"
"src/main/cpp/*.hpp"
)
#
add_library( myLib SHARED ${CPP_SRC} )
#
find_library( log-lib log )
#
target_link_libraries( myLib libopencv ${log-lib} )
target_link_libraries( myLib android log EGL GLESv2 )
In my jniLibs -> arm64-v8a
I have those cv libs:
libopencv_calib3d.a, libopencv_core.a, libopencv_dnn.a, libopencv_features2d.a libopencv_flann.a, libopencv_highgui.a, libopencv_imgcodecs.a, libopencv_imgproc.a, libopencv_java3.so, libopencv_ml.a, libopencv_objdetect.a, libopencv_photo.a, libopencv_shape.a libopencv_stitching.a, libopencv_superres.a, libopencv_video.a, libopencv_videoio.a, libopencv_videostab.a
As I said other cv function like cv::solvePnP
work fine.
only KnnMatch
throw undifined.
UPDATE: If I'm remove -DANDROID_STL=c++_shared
I can compile knnMatch
but I need it, any suggestions?