How to use opencv on Android Studio with Jni call

asked 2016-11-27 19:57:15 -0600

Hi all,

Refrence to pure java to develop OpenCV demo , we can import new module *OpenCV-android-sdk\sdk\java* as a module dependencies for android project. Using this way, Android Studio will give the tips of functions and so on. Now I wanna do the same thing when I use Jni, see below please:

JNIEXPORT jintArray JNICALL Java_com_ckt_eirot_opencv4jni_GrayProcess_grayProcess(JNIEnv *env, class obj,jintArray buf,jint w, jint h) { jboolean ptfalse = false; jint *srcBuf = env->GetIntArrayElements(buf, &ptfalse); if (srcBuf == NULL) { return 0; } int size = w * h;

**Mat** srcImage(h, w, CV_8UC4, (unsigned char *) srcBuf);
**Mat** grayImage;

// when I type the part of bold function  like cvt… , I want to AS give me a tip of the usage
**cvtColor**(srcImage, grayImage, COLOR_BGRA2GRAY);
**cvtColor**(grayImage, srcImage, COLOR_GRAY2BGRA);

jintArray result = env->NewIntArray(size);
env->SetIntArrayRegion(result, 0, size, srcBuf);
env->ReleaseIntArrayElements(buf, srcBuf, 0);

return result;

}

Looking forward to replies

edit retag flag offensive close merge delete

Comments

See if you find this link useful

abhijith gravatar imageabhijith ( 2016-11-28 02:58:39 -0600 )edit

If I understand you right, you want to add the OpenCV c++ Library to your Android Project, so it shows you tipps when you type the functions? If yes, look at the Answer here That will tell you how to add the OpenCV c++ Library to your Android Project. After that, you just have to #include the .hpp Files with the functions you need, and Android Studio should show you the tips and so on.

Vintez gravatar imageVintez ( 2016-11-28 07:43:01 -0600 )edit

Thanks for your reply! Your posted link is helpful . Recently, I have found the solution and solved the problem by using cmake to include the OpenCV native header for my project. Here is my study wiki:

http://cxuef.github.io/android/Androi...

Eirot gravatar imageEirot ( 2016-11-29 03:02:32 -0600 )edit