Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

When I use 'cvtColor' with JNI, Console says: Fatal signal 11 (SIGSEGV), code 1, fault addr 0xa4400000 in tid 3689

Recently, I try using OpenCV at Android.I write a native method´╝îand use it at java.

JNIEXPORT jintArray JNICALL Java_yu_myself_opencv_jni_OpenCVHelper_canny(
JNIEnv *env, jclass obj, jintArray buf, int w, int h){

jint *cbuf;
cbuf = env->GetIntArrayElements(buf, JNI_FALSE);
if (cbuf == NULL) {
    return 0;
}

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

Mat grayImage(srcImage.size(), srcImage.type());
LOGD("1");
cvtColor(srcImage, grayImage, COLOR_BGRA2GRAY);
LOGD("2");
jint* ptr = (jint*)grayImage.ptr(0);
LOGD("3");
int size = w * h;
LOGD("4");
jintArray result = env->NewIntArray(size);
LOGD("5");
env->SetIntArrayRegion(result, 0, size, ptr);
LOGD("6");
env->ReleaseIntArrayElements(buf, cbuf, 0);
LOGD("7");
return result;
}

But it crashed.I see the result of console:

07-05 17:32:16.721 3689-3689/yu.myself.opencv D/NDK/OpenCVHelper: 1
07-05 17:32:16.727 3689-3689/yu.myself.opencv D/NDK/OpenCVHelper: 2
07-05 17:32:16.728 3689-3689/yu.myself.opencv D/NDK/OpenCVHelper: 3
07-05 17:32:16.728 3689-3689/yu.myself.opencv D/NDK/OpenCVHelper: 4
07-05 17:32:16.739 3689-3689/yu.myself.opencv D/NDK/OpenCVHelper: 5
07-05 17:32:16.743 3689-3689/yu.myself.opencv A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0xa4400000 in tid 3689 (u.myself.opencv)

I don't know why there is such a problem. What should I do?