【发布时间】:2016-03-29 07:56:01
【问题描述】:
我查看了所有内容,但我不明白为什么会收到致命信号 11。
Java端:
mRgba = inputFrame.rgba();
String nativeTesting = mNativeDetector.getFeatures(mRgba);
Log.e(TAG, nativeTesting);
// In another class
public String getFeatures(Mat image) {
Log.e("FRAME", " Rows:" +image.rows()); // This correctly returns the number of rows
String resultMsg = nativeFeatures(mNativeObj, image.getNativeObjAddr());
return resultMsg;
}
C++ 方面:
JNIEXPORT jstring JNICALL Java_com_example_myfacedetection_DetectionBasedTracker_nativeFeatures (JNIEnv* env, jclass, jlong image){
LOGD("NativeFeatures enter");
try {
Mat* frame = (Mat*) image;
// if (frame.empty()) // This also results in Fatal Signal
// LOGD("EMPTY FRAME");
LOGD("Size: %d", frame->rows);
}
catch(cv::Exception& e)
{
LOGD("nativeCreateObject caught cv::Exception: %s", e.what());
jclass je = env->FindClass("org/opencv/core/CvException");
if(!je)
je = env->FindClass("java/lang/Exception");
env->ThrowNew(je, e.what());
}
return (env)->NewStringUTF("Hello from JNI !");
}
我正在尝试计算直方图,但对帧的任何访问都会导致 SegFault。我做错了什么?
【问题讨论】:
-
您的本机函数只接受一个参数(
long),但您从 Java 代码中传递了两个参数。根据您向我们展示的代码,我看不出您如何没有收到 UnsatisfiedLinkError。 -
JNI 使用 C 链接(无名称修改),因此链接器只寻找
Java_com_example_myfacedetection_DetectionBasedTracker_nativeFeatures并找到它就好了。
标签: java android c++ opencv java-native-interface