Ask Your Question

Revision history [back]

  1. FaceRecognizer like all Java wrappers has nativeObj field that stores pointer to native OpenCV object. So you do not need to construct native object manually. You just can pass value of nativeObj to any JNI function and use it as pointer on conrespondent C++ object in JNI code.
  2. cv::Ptr is a smart pointer with reference counting. In JNI code it calls object destruction after on exit from function body. That's why you get invalid object and strange segfault. You need to reorganize JNI part in way like this:

    JNIEXPORT jlong JNICALL Java_org_opencv_samples_fd_LBPFaceRecognizer_nativeCreateObject (JNIEnv * jenv, jclass) { FaceRecognizer* model = createLBPHFaceRecognizer();
    return (jlong)model; }

Also you need to implement some release() method for native object destruction.