Я пытаюсь написать приложение для Android, используя OpenCV и Jni для сравнения изображений и поиска совпадений.Я уже использую OpenCV 3.2.0 (используя официальный готовый пакет Android) в Android успешно.Но когда я пытаюсь использовать функцию knnMatch, она выдает мне следующее сообщение об ошибке:
Build command failed.
Error while executing process
D:\Android\sdk\cmake\3.6.4111459\bin\cmake.exe with arguments {--build
C:\Users\Amine\Desktop\testtt\app\.externalNativeBuild\cmake\debug\arm64-
v8a --target native-lib}
[1/2] Building CXX object CMakeFiles/native-lib.dir/src/main/cpp/native-
lib.cpp.o
[2/2] Linking CXX shared library
..\..\..\..\build\intermediates\cmake\debug\obj\arm64-v8a\libnative-lib.so
FAILED: cmd.exe /C "cd . && D:\Android\sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=aarch64-none-linux-android21 --gcc-toolchain=D:/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64 -fPIC --sysroot
D:/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/sysroot -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fno-addrsig -Wa,--noexecstack -Wformat -Werror=format-security -stdlib=libc++ -frtti -fexceptions -std=gnu++11 -O0 -fno-limit-debug-info -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -static-libstdc++ -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined -Qunused-arguments -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,libnative-lib.so -o ..\..\..\..\build\intermediates\cmake\debug\obj\arm64-v8a\libnative-lib.so
CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o ../../../../src/main/jniLibs/arm64-v8a/libopencv_java3.so -latomic -lm && cd ."
CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o: In function `toGray(cv::Mat&, cv::Mat&)':
C:\Users\Amine\Desktop\testtt\app\src\main\cpp/native-lib.cpp:216: undefined reference to `cv::DescriptorMatcher::knnMatch(cv::_InputArray const&, cv::_InputArray const&, std::__ndk1::vector<std::__ndk1::vector<cv::DMatch, std::__ndk1::allocator<cv::DMatch> >, std::__ndk1::allocator<std::__ndk1::vector<cv::DMatch, std::__ndk1::allocator<cv::DMatch> > > >&, int, cv::_InputArray const&, bool) const'
C:\Users\Amine\Desktop\testtt\app\src\main\cpp/native-lib.cpp:220: undefined reference to `cv::DescriptorMatcher::knnMatch(cv::_InputArray const&, cv::_InputArray const&, std::__ndk1::vector<std::__ndk1::vector<cv::DMatch, std::__ndk1::allocator<cv::DMatch> >, std::__ndk1::allocator<std::__ndk1::vector<cv::DMatch, std::__ndk1::allocator<cv::DMatch> > > >&, int, cv::_InputArray const&, bool) const'
clang ++. Exe: error: сбой команды компоновщика с кодом выхода 1 (используйте -v для просмотра вызова)
Вот мой код cpp:
std::vector<cv::KeyPoint> keypointsCaptured;
std::vector<cv::KeyPoint> keypointsTarget;
cv::Mat descriptorsCaptured;
cv::Mat descriptorsTarget;
//cv::Mat captured;
std::vector<cv::DMatch> matches;
std::vector<cv::DMatch> symMatches;
orb = ORB::create();
//Pre-process
resize(captured, captured, Size(480,360));
medianBlur(captured, captured, 5);
resize(target, target, Size(480,360));
medianBlur(target, target, 5);
orb->detectAndCompute(captured, noArray(), keypointsCaptured, descriptorsCaptured);
orb->detectAndCompute(target, noArray(), keypointsTarget, descriptorsTarget);
//__android_log_print(ANDROID_LOG_INFO, "sometag", "keypoints2 size = %d", keypointsTarget.size());
//__android_log_print(ANDROID_LOG_INFO, "sometag", "keypoints size = %d", keypointsCaptured.size());
//Match images based on k nearest neighbour
std::vector<std::vector<cv::DMatch> > matches1;
matcher.knnMatch(descriptorsCaptured , descriptorsTarget,
matches1, 2);
//__android_log_print(ANDROID_LOG_INFO, "sometag", "Matches1 = %d", matches1.size());
std::vector<std::vector<cv::DMatch> > matches2;
matcher.knnMatch(descriptorsTarget , descriptorsCaptured,
matches2, 2);
//Ratio filter
ratioTest(matches1);
ratioTest(matches2);
symmetryTest(matches1,matches2,symMatches);
ransacTest(symMatches,
keypointsCaptured, keypointsTarget, matches);