Ask Your Question

Yuruxuan's profile - activity

2016-07-07 03:39:43 -0600 received badge  Scholar (source)
2016-07-07 03:39:40 -0600 received badge  Supporter (source)
2016-07-06 08:57:01 -0600 commented answer When I use 'cvtColor' with JNI, Console says: Fatal signal 11 (SIGSEGV), code 1, fault addr 0xa4400000 in tid 3689

perfect!Because Android does not support one channel,I must convert twice:RGB->Gray->RGB.Then the gray image is display normal.

2016-07-05 05:32:18 -0600 asked a question 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?