Using Android Studio's C++ support to build nonfree OpenCV modules

为君一笑 提交于 2019-12-17 19:33:32

问题


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?

来源:https://stackoverflow.com/questions/44079701/using-android-studios-c-support-to-build-nonfree-opencv-modules

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!