Ask Your Question
0

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

asked 2016-07-05 05:15:03 -0600

Yuruxuan gravatar image

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?

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
3

answered 2016-07-06 07:30:52 -0600

Daniil Osokin gravatar image

The obtained grayscale image is of type CV_8UC1, so use Byte instead of Int infix in function names (e.g. NewByteArray, ...), or convert grayscale to BGRA once again and use it instead.

edit flag offensive delete link more

Comments

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

Yuruxuan gravatar imageYuruxuan ( 2016-07-06 08:31:20 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-07-05 05:15:03 -0600

Seen: 1,312 times

Last updated: Jul 06 '16