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

0

21

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][1] 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?

Washburn answered 19/5, 2017 at 22:13 Comment(5)
You want to access the Java contrib API? or are you open to code in C++ using NDKFlu
The goal is to use Java; a goodly fraction of Android developers are not as well versed in C++.Washburn
I am also looking for that, were you successful in the implementation of that?Petrochemistry
SIFT is protected by a patent. If you use it in you're program you are exposing yourself to a lawsuit. And you've announced your intention to violate the patent in a public place. ??? The good news is that the patent expires around March 2020, so if can wait to release your app, you should be able to do it then. Alternatively you can try the ORB algorithm which was always free. But I'm not gonna lie, SIFT is a little better than ORB.Arkose
@Arkose Thanks for the reply. I would not be breaking any laws as long as I was just fiddling with SIFT myself, which is my plan. Great news about the expiring patent!Washburn

© 2022 - 2024 — McMap. All rights reserved.