I want to use OpenCV library in both my Java codes and JNI C++ codes in Android Studio.
How can I import OpenCV library and set up the NDK environment (JNI) in the same android project in Android Studio?
I could successfully do either one, but could not do both in a project even though I have tried many times.
I followed these two tutorials to set up the environment.
1. OpenCV for android
2.JNI/NDK
Does anyone have any idea why my setup was failed?
Or can anyone provide me a guide to set up the environment?
Related
I have gone through all the Android NDK tutorials and built a few simple examples. It seems to me that every example out there from Android Studio revolves around creating a native library attached to an Android application directly. I need to create a native library that is attached to an already existing Android Library. I don't see an example to do this. Is it even possible to hang a native C++ library off an already existing Android Java Library, so the Android Library has access to those native methods, without attaching both libraries (android and native) to a specific application?
Tried in Android Studio to attach a C++ native library to an already existing Android Library, and used CMake as compiler choice, the gradle does not seem to support. The CMakeLists.txt does not seem to be recognized, the "includes" folder is not generated to support the .cpp in the cpp folder, and the native library generates no links I can see to the Android Library methods.
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?
I want to use native C++ code of Opencv in android studio 2.2.2 .I tried about a week reading tutorials but that didn't work for me.I am new to opencv and android.It would be quite helpful if I get step by step instruction for doing this.
Hi, I'm new to android developing with NDK , I'm using ndk-r9d and cocos2d-x 2.2.3.
When I create a project with cocos and import to Eclipse , in the conversion phase the name of the project not shown in the candidate for conversion section of convert to a C`C++` project.
Can anyone help me???
It might well be that the project is already with C/C++ nature,
you said you have the C++ menus,
do you also have for example this menu in the image?
If so, you're good to go and start compiling C++ code.
try using the eclipse c/c++ development. I was also facing same issue when using eclipse for java/jee development. I simply added C/C++ support by downloading packages to Java/Jee eclipse. After installing proper eclipse for c/C++ development, I was able to see "convert to c/C++...." option.
I am new to android and opencv,and I am going to develop a APP using this code with this link
here
http://geekoverdose.wordpress.com/category/computer-vision/
The sample project says that "you will have to get the opencv libraries precompiled" in here what I want to do for run this code correctly.please consider about this issue. in here it is wanted to consider about opencv installation for android or is there any special thing have to do? thank you
It will take a little more effort to "run this code" correctly. In short, JavaCV is a wrapper on top of OpenCV, and you have to compile the OpenCV and correctly move all the shared libraries (.so) to your Android development project etc. Like the original article suggested, you need to go to JavaCV homepage and read the installation instructions.