Using Android Studio's C++ support to build no

2020-02-05 12:47发布

问题:

Background

Although older versions of OpenCV (ie 2.4) allow Android projects to utilize SIFT functionality, the separation of that functionality into opencv_contrib makes the task more difficult; integrating a OpenCV-3.x.x-android-sdk module into a project leaves you without the ability to use the SIFT functionality.

FeatureDetector.create(FeatureDetector.DYNAMIC_SIFT); // Fails
//OpenCV Error: Bad argument (Specified feature detector type is not supported.)

Using External Tools

Although there are techniques such as Gouhui Wang's that describe how to build the nonfree portion of OpenCV into an Android project, that process requires external tools. This question is about how to get the same result, but instead leverage the power and convenience of the Android Studio / InteliJ.

Using CMake in Android Studio

Modern Android Studio versions have useful functionality:

Using Android Studio 2.2 and higher, you can use the NDK to compile C and C++ code into a native library and package it into your APK using Gradle, the IDE's integrated build system. Your Java code can then call functions in your native library through the Java Native Interface (JNI)

As indicated in this stackoverflow question and answer concerning building OpenCV with C++ support, it is possible to quickly integrate OpenCV 3.1 (and I suspect other versions) of opencv4android into the C++ build structure that's generated in the new application wizard.

I suspect that someone that understands the details of building projects could utilize Building_OpenCV4Android_from_trunk to answer this question. My expertise in this area is limited, thus, the question.

What specific steps would be required in order to get the nonfree portion of OpenCV to build completely within the native Android Studio build process?