未定义对"cv :: CascadeClassifier :: detectMultiScale"的引用,但其他库已正确链接 [英] undefined reference to 'cv::CascadeClassifier::detectMultiScale', but other lib linked properly

查看:254
本文介绍了未定义对"cv :: CascadeClassifier :: detectMultiScale"的引用,但其他库已正确链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用NDK执行一些opencv函数,以查看使用c ++是否可以加快处理速度(我在另一个项目中使用了Java Wrappers).一切都很好,直到我在类中添加了 detectMultiScale 函数,链接器突然失败并产生了未定义的引用错误.如果我注释掉该行,该错误将消失.

I am using NDK to perform some opencv functions to see if using c++ will speed up the processing (I used Java Wrappers in another project). All was compiling fine until I added the detectMultiScale function in my class where suddenly the linker failed and produced the undefined reference error. The error will go away if I comment out that line.

我在网上搜索了所有内容,但除了 https://之外,似乎没有人遇到过同样的问题stackoverflow.com/questions/32022597/undefined-reference-to-cascadeclassifierdetectmultiscale ,其中没有建议答案.如果有人可以找到其他相关的帖子,请随时将我引导到这里:)

I searched all over the net but no one seems to have the same problem aside from https://stackoverflow.com/questions/32022597/undefined-reference-to-cascadeclassifierdetectmultiscale where no answers were suggested. If anyone can find another relevant post, feel free to direct me there :)

平台:Windows 10, Android Studio 2 OpenCV 3.1(重新编译以添加人脸模块)

Platform: Windows 10, Android Studio 2, OpenCV 3.1 (recompiled myself to add the 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

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 $(

执行ndk构建时出现以下错误

And I got the following error while performing 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 there's more information you all need, just ask, I'll try to provide as much information as possible.

推荐答案

经过长时间的调查和测试,我发现此问题位于我的 Application.mk 中.添加以下行可解决问题;

After long investigation and testing, I found the problem located in my Application.mk. Adding the following line fix the problem;

APP_STL:=gnustl_shared

响应让我思考我是否缺少stl.

Got the idea from this response that make me think whether I'm missing stl.

这篇关于未定义对"cv :: CascadeClassifier :: detectMultiScale"的引用,但其他库已正确链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆