Ask Your Question

Revision history [back]

How to use opencv on Android Studio with Jni call

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