Home > other >  The error on the Android and OpenCV 3.4.0 associated with the NDK
The error on the Android and OpenCV 3.4.0 associated with the NDK

Time:12-06

I am trying to use OpenCV existing computer vision of written in C code ported to the Android the NDK. I according to the information provided herein for the Java and the NDK successfully imported the OpenCV library version 3.4.0 (using the official pre-built Android package) : Satck Overflow Answer - CMake configuration of OpenCV on Android.
I will be able to use the OpenCV function to compile and run the Java and C code. However, I met with some OpenCV function related to the two "undefined reference" link error: persistence JSON reader and 2 d descriptor matcher.
The following is I receive an error message:

The Build command failed.
Error while executing process D: \ Librairies \ Android_SDK \ cmake \ 3.6.4111459 \ bin \ cmake exe with the arguments {- build D:/Dev/Android/PageDetector \ app \. ExternalNativeBuild \ cmake \ debug \ x86_64 -- target page - recognition - lib}
[1/1] Linking CXX Shared library.. \.. \.. \../build/intermediates/cmake \ debug \ obj \ x86_64 \ recognition - lib. So
FAILED: CMD. Exe/C "CD & amp; & D:\Librairies\Android_SDK\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=x86_64-none-linux-android --gcc-toolchain=D:/Librairies/Android_SDK/ndk-bundle/toolchains/x86_64-4.9/prebuilt/windows-x86_64 --sysroot=D:/Librairies/Android_SDK/ndk-bundle/sysroot -fPIC -isystem D:/Librairies/Android_SDK/ndk-bundle/sysroot/usr/include/x86_64-linux-android -D__ANDROID_API__=21 -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -Wa,--noexecstack -Wformat -Werror=format-security -std=c++11 -std=c++11 -frtti -fexceptions -std=gnu++11 -O0 -fno-limit-debug-info -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -nostdlib++ --sysroot D:/Librairies/Android_SDK/ndk-bundle/platforms/android-21/arch-x86_64 -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -LD:/Librairies/Android_SDK/ndk-bundle/sources/cxx-stl/llvm-libc++/libs/x86_64 -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,libpage-recognition-lib.so -o .. \.. \.. \../build/intermediates/cmake \ debug \ obj \ x86_64 \ recognition - lib. So. So [...]. - llog - llog../../../../SRC/main/jniLibs/x86_64/libopencv_java3. So - latomic - lm "D:/Librairies/Android_SDK/the NDK - bundle/sources/CXX - the STL/LLVM - libc++/libs/x86_64/libc++ _static. A" "D:/Librairies/Android_SDK/the NDK - bundle/sources/CXX - the STL/LLVM - libc++/libs/x86_64/libc++ abi. A" & amp; & CD. "
D:/Librairies OpenCV - android - sdk_340/SDK/native/jni/include \ opencv2/core/personal HPP: 1264: error: undefined reference to 'CV: : read (CV: : FileNode const& , STD: : __ndk1: : vector & amp;) '
D:/Dev/Android/PageDetector \ app \ SRC \ main \ CPP/PageMatcher CPP: 170: error: undefined reference to 'CV: : DescriptorMatcher: : radiusMatch (CV: : _InputArray const& , CV: : _InputArray const& , STD: : __ndk1: : vector , STD: : __ndk1: : allocator> & , float, CV: : _InputArray const& Const, bool '
Clang++. Exe: error: would the command failed with exit code 1 (use the -v to see invocation)
Ninja: build stopped: subcommand failed.

The following is the compiler cannot link code:

//code that reads data from a JSON file
This - & gt; JSONFeatureFilePath=JSONFeatureFilePath;
CV: : FileStorage reader (JSONFeatureFilePath, CV: : FileStorage: : READ);

This - & gt; BookTitle=(string) reader [" book_title "];
This - & gt; PageNumber=(int) reader (" page_num ");

String descType=(string) reader (" desc_type ");
The replace (descType. The begin (), descType. The end (), '_', '. ');
This - & gt; DescriptorType=descType;

Reader [" img_size "] & gt;> This - & gt; ImageSize;

//this instruction causes the would error
Reader [" keypoints "] & gt;> This - & gt; KeyPoints.

Reader [" descriptors] & gt;> This - & gt; KeyPointDescriptors;
Reader [" fsum2d "] & gt;> This - & gt; Fsum2DFeatureSummary;

Reader. Release ();

And

//code performing key point descriptors matching
CV: : Ptr The matcher=CV: : DescriptorMatcher: : create (CV: : DescriptorMatcher: : BRUTEFORCE_HAMMING);

Vector MatchesTmp;

//instruction is responsible for the link error
The matcher - & gt; RadiusMatch (this - & gt; SortedMatches. Ats (refSortedIndex). RefImage - & gt; GetDescriptors (),
This - & gt; TestImage - & gt; GetDescriptors (), matchesTmp matchThreshold);

I have clearly identified the causes the linker error of line, as described in the code sample below. If I comment out them, compiler will finish and program is running normal (of course not I tried to realize the functions in the NDK).
My guess is that I call the OpenCV function in the absence of pre-built libraries, or for the NDK development of compiler is not compatible with me. I have tried to change the version of the OpenCV (3.3.0 and 3.4.0).
Does anyone know what causes this kind of situation, and how to solve this problem? It is known in OpenCV error or my configuration is not supported or just a mistake?
10 computer I'm using Windows and Android Studio 3.1.2, the NDK r17, build tools 27.0.3 and OpenCV 3.4.0 pre-built Android package (I don't have yourself from source code to compile.) here is CMake and build gradle file:
CMake:

Cmake_minimum_required (VERSION 3.4.1 track)

Set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} - STD=gnu++ 11")
Set (opencv_340_dir D:/Librairies OpenCV - android - sdk_340/SDK/native/jni)
Set (app_dir D:/Dev/Android/PageDetector/app)

# native recognition library API
Add_library (recognition - lib
SHARED
SRC/main/CPP/recognition - lib. H
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related