Undefined reference to 'cv :: CascadeClassifier :: detectMultiScale', but a different lib associated with it

I am using NDK to execute some opencv functions to see if using C ++ will speed up processing (I used Java Wrappers on another project). Everything was compiling until I added the detectMultiScale function to my class, where suddenly the linker compiled and produced an undefined reference error . The error will be skipped if I comment this line.

I've searched all over the net, but no one seems to have the same problem, except for an undefined reference to CascadeClassifier :: detectMultiScale where there were no answers. If anyone can find another relevant post, feel free to direct me there :)

Platform: Windows 10, Android Studio 2, OpenCV 3.1 (recompiled to add a face module)

main.cpp

#include <jni.h>
#include <string>
#include <android/log.h>
#include "com_yk_iskl_jnitest_FaceRecognition.h"


#define  LOG_TAG    "libnativeface"
#define  LOGI(...)  __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
#define  LOGW(...)  __android_log_print(ANDROID_LOG_WARN,LOG_TAG,__VA_ARGS__)
#define  LOGE(...)  __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)

class FaceRecognition{
private:
    cv::Ptr<cv::face::LBPHFaceRecognizer> lbph_model;
    cv::Ptr<cv::face::FaceRecognizer> fisher_model;
    cv::Ptr<cv::face::FaceRecognizer> eigen_model;

    cv::CascadeClassifier face_cascade;
    cv::CascadeClassifier eye_cascade;

public:
    void loadLBPHModel(std::string& filepath)
    {
        lbph_model=cv::face::createLBPHFaceRecognizer();
        try{
            lbph_model->load(filepath);
        }catch(cv::Exception e){
            LOGE("%s",(e.msg).c_str());
        }
        lbph_model->setThreshold(999);
    }

    void loadFaceCascade(std::string& filepath)
    {
        try{
            face_cascade.load(filepath);
        }catch(cv::Exception e){
            LOGE("%s",(e.msg).c_str());
        }
    }

    void loadEyeCascade(std::string& filepath)
    {
        try{
            eye_cascade.load(filepath);
        }catch(cv::Exception e){
            LOGE("%s",(e.msg).c_str());
        }
    }

    double getThreshold()
    {
        return lbph_model->getThreshold();
    }

    std::vector<cv::Rect> detectFace(cv::Mat src)
    {
        std::vector<cv::Rect> faces;
        face_cascade.detectMultiScale(src, faces, 1.1, 2, 0 | cv::CASCADE_SCALE_IMAGE, cv::Size(30, 30)); <--------------------------Heres the problem
        return faces;
    }
};
//---------------------------
JNIEXPORT jlong JNICALL
Java_com_yk_iskl_jnitest_FaceRecognition_createNativeFaceRecognition(JNIEnv *, jclass)
{
    return (jlong)(new FaceRecognition());
}


JNIEXPORT void JNICALL
Java_com_yk_iskl_jnitest_FaceRecognition_loadLBPHModel(JNIEnv * env, jclass, jlong native_addr, jstring filename)
{
    std::string fn((const char*)env->GetStringUTFChars(filename,0));
    ((FaceRecognition*)native_addr)->loadEyeCascade(fn);
}

JNIEXPORT void JNICALL
Java_com_yk_iskl_jnitest_FaceRecognition_loadEyeCascade(JNIEnv * env, jclass, jlong native_addr, jstring filename)
{
std::string fn((const char*)env->GetStringUTFChars(filename,0));
((FaceRecognition*)native_addr)->loadLBPHModel(fn);
}

JNIEXPORT jdouble JNICALL
Java_com_yk_iskl_jnitest_FaceRecognition_getThreshold(JNIEnv *env, jclass, jlong native_addr)
{
return (jdouble)((FaceRecognition*)native_addr)->getThreshold();
}

JNIEXPORT void JNICALL
Java_com_yk_iskl_jnitest_FaceRecognition_process(JNIEnv *env, jclass, jlong native_addr, jlong frame_addr)
{
    cv::Mat* pframe_addr = (cv::Mat*)frame_addr;
    cv::cvtColor(*pframe_addr,*pframe_addr,cv::COLOR_YUV420sp2GRAY);
    std::vector<cv::Rect> faces=((FaceRecognition*)native_addr)->detectFace(*pframe_addr);
}

JNIEXPORT void JNICALL
Java_com_yk_iskl_jnitest_FaceRecognition_testReturns(JNIEnv *env, jclass, jlong native_addr, jobjectArray string, jintArray num)
{
    //Get pointer from num
    jint* parray=env->GetIntArrayElements(num,0);

    parray[0]=888;

    //Copy back to num
    env->SetIntArrayRegion(num,0,1,parray);

}
//---------------------------

      

Android.mk

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

#opencv
OPENCVROOT:= C:\Users\<hidden>\Desktop\PROGRAMMING\OPENCV_ANDROID_BUILD\install
OPENCV_CAMERA_MODULES:=on
OPENCV_INSTALL_MODULES:=on
OPENCV_LIB_TYPE:=SHARED
include ${OPENCVROOT}\sdk\native\jni\OpenCV.mk

#include $(CLEAR_VARS)
LOCAL_SRC_FILES := main.cpp
LOCAL_LDLIBS += -lz -lm -llog -landroid -ldl
LOCAL_MODULE := nativeface

include $(

      

And I got the following error when doing ndk build

 C:/Users/<hidden>/AndroidStudioProjects/JNITEST/app/src/main/jni/main.cpp:59: error: undefined reference to 'cv::CascadeClassifier::detectMultiScale(cv::_InputArray const&, std::__ndk1::vector<cv::Rect_<int>, std::__ndk1::allocator<cv::Rect_<int> > >&, double, int, int, cv::Size_<int>, cv::Size_<int>)'
collect2.exe: error: ld returned 1 exit status
make: *** [C:\Users\<hidden>\AndroidStudioProjects\JNITEST\app/build/intermediates/ndk/obj/local/armeabi-v7a/libnativeface.so] Error 1

      

If you need more information, just ask, I will try to provide as much information as possible. Thanks in extended

+2


source to share


1 answer


After a lot of research and testing, I found the problem located in my Application.mk . Adding the following line fix the problem;

APP_STL:=gnustl_shared

      



Got an idea from this answer that makes me think if I am missing stl.

0


source







All Articles