Is it compulsory to install opencv manager on android device if we are trying to make application using opencv
ndk ? Is there any alternative of it so that one don't have to install opencv manager because it looks weird if customer need to install opencv manager with our application too.

- 553
- 8
- 31
-
check below links http://stackoverflow.com/questions/20259309/how-to-integrate-opencv-manager-in-android-app http://stackoverflow.com/questions/12615712/static-initialization-on-opencv-android – Arash Aug 22 '14 at 16:55
2 Answers
If you are doing the complete image processing part using OpenCV NDK (which is quite possible) , OpenCV manager is not needed. The data from the camera preview can be passed to your function written in native C/C++. There you can convert to BGR/BGRA. An outline of that would be like the following.
Code in Java
public native void jniPart(int width, int height, byte[] data);
where width and height are the width and height of the image/camera preview. I am assuming here that you are processing the framees from the camera. In that case you can pass the the data from the camera which comes as a byte array.
In the C/C++ code you can convert the camera data to BGR using the following snippet. Note that the default camera image format in most android OS are NV21, but you can change that.
Code in C/C++
JNIEXPORT jstring JNICALL Java_com_example_AppName_ClassName_jniPart (JNIEnv* env, jobject j_this,jint width, jint height, jbyteArray yuvdata){
.
.
jbyte* _yuv = env->GetByteArrayElements(yuv, 0);
Mat nv21img(height + height/2, width, CV_8UC1, (unsigned char *)_yuv);
Mat matImg(height, width, CV_8UC3) ;
cvtColor(nv21img,matImg,CV_YUV2BGR_NV21, 4);
.
}
You can now use the matImg to do the processing. Integration of the opencv Manager can be avoided in this case. All you have to do is to make sure that the makefile has correct link to the opencv.mk .

- 630
- 7
- 9
-
So, you mean only the OpenCV Java interface needs the OpenCV manager? – Abhijat Biswas Jul 11 '15 at 22:13
-
Yes, as the Java library binaries are provided by the Manager. The downside of doing everything in NDK is that it would increase the app size as all the statically linked libraries now become a part of the app. – patel deven Jul 13 '15 at 05:57
-
But say I was running a native activity, how would I link the C++ libs? OpenCV Manager does that for me doesn't it? – Abhijat Biswas Jul 13 '15 at 09:52
-
1OpenCV manager would not be required for C/C++ libraries. [link](http://docs.opencv.org/doc/tutorials/introduction/android_binary_package/android_dev_intro.html#android-application-structure ) After a successful build (via ndk-build), the libs folder of your project will contain native libraries. You do not have to load the Manager in the Java code. Only if you are using OpenCV functions in your Java code, you would need the opencv manager. – patel deven Jul 14 '15 at 07:00
you can call initDebug and 'statically' link against your opencv libs, but that comes with the drawback, that you will now have to supply different versions of your apk, and make sure, that your customers get the right one.
so, it's possible, but not the recommended method.

- 39,159
- 9
- 91
- 89
-
berak i tried it statically but it still demanding opencv manager , though isn't it make the application much heavy ? and initDebug can use in c++ with ndk ? – Rocket Jul 25 '14 at 12:35
-
have not tried with own ndk components, but again, i think they're quite clear on this: "If you want to publish your app use approach with async initialization." – berak Jul 25 '14 at 12:41
-
so when we load it something like this `static boolean initAsync(OPENCV_VERSION_2_4_8, Context AppContext, LoaderCallbackInterface Callback)` then we don't need opencv library in our workspace or in our project – Rocket Jul 26 '14 at 15:59