代码之家  ›  专栏  ›  技术社区  ›  Jena43

如何在Android的qt中使用/link opencv 3.4.1?

  •  1
  • Jena43  · 技术社区  · 6 年前

    我想在我的Qt中为Android项目使用Opencv3.4.1,但是我得到了构建错误,例如:

    .../libopencv_core.a(system.cpp.o):system.cpp:function cv::HWFeatures::initialize(): error: undefined reference to 'android_getCpuFeatures'
    .../libopencv_core.a(arithm.cpp.o):arithm.cpp:function cv::hal::cmp8u(unsigned char const*, unsigned int, unsigned char const*, unsigned int, unsigned char*, unsigned int, int, int, void*): error: undefined reference to 'carotene_o4t::isSupportedConfiguration()'
    .../libopencv_core.a(arithm.cpp.o):arithm.cpp:function cv::hal::cmp8u(unsigned char const*, unsigned int, unsigned char const*, unsigned int, unsigned char*, unsigned int, int, int, void*): error: undefined reference to 'carotene_o4t::cmpGE(carotene_o4t::Size2D const&, unsigned char const*, int, unsigned char const*, int, unsigned char*, int)'
    

    Full error file here (对于堆栈溢出来说太大)

    这是我在我的*.pro文件中写的:

    QT += core quick quickcontrols2 widgets
    CONFIG += c++11 console
    
    #...
    
    OPENCVSDKNATIVE = $$PWD/3rdparty/opencv-3.4.1-android-sdk/sdk/native
    
    INCLUDEPATH += $$OPENCVSDKNATIVE/jni/include
    
    equals(ANDROID_TARGET_ARCH, armeabi-v7a) {
        message("setting armeabi-v7a OPENCV libs")
    
        # OPENCV LIBS
        LIBS += -L"$$OPENCVSDKNATIVE/3rdparty/libs/armeabi-v7a" -llibtiff -llibjpeg -llibjasper -llibpng -llibwebp -lIlmImf -ltbb -ltegra_hal
        LIBS += -L"$$OPENCVSDKNATIVE/staticlibs/armeabi-v7a" -lopencv_core -lopencv_imgcodecs -lopencv_imgproc
    
        ANDROID_EXTRA_LIBS += $$OPENCVSDKNATIVE/libs/armeabi-v7a/libopencv_java3.so
    }
    

    我在CPP代码中写的是:

    #include <opencv2/core/core.hpp>
    #include <opencv2/imgproc/imgproc.hpp>
    #include <opencv2/imgcodecs/imgcodecs.hpp>
    
    int main (int argc, char *argv[]){
        QString imgPath = "path_to_my_image.jpg";     
        cv::Mat image = cv::imread(imgPath.toStdString().c_str());
        //...
    }
    

    如何在Android的qt中使用/link opencv 3.4.1?

    使用的版本:

    • OpenCv SDK for Android 3.4.1自 here .
    • 第5.10.1节
    • Qt创建者4.6.1
    • android for armeabi-v7a(GCC 4.9,Qt 5.10.1 for android armv72)版本

    编辑1 :我更新了*.pro文件中的libs var,但仍有问题

    LIBS +=\
        -L"$$OPENCVSDKNATIVE/3rdparty/libs/armeabi-v7a"\
        -L"$$OPENCVSDKNATIVE/staticlibs/armeabi-v7a"\
        -llibtiff -llibjpeg -llibjasper -llibpng -lIlmImf   -llibprotobuf\
        -lopencv_core -lopencv_imgproc -lopencv_imgcodecs\
        -ltbb -lcpufeatures -ltegra_hal
    
    1 回复  |  直到 6 年前
        1
  •  1
  •   Jena43    6 年前

    出现问题的原因是 LIBS *.pro文件中的var。

    这是一个有效的(我补充说 -lcpufeatures 把伦敦银行同业拆放整齐)

        LIBS +=\
        -L"$$OPENCVSDKNATIVE/3rdparty/libs/armeabi-v7a"\
        -L"$$OPENCVSDKNATIVE/staticlibs/armeabi-v7a"\
         -lopencv_imgcodecs -lopencv_imgproc -lopencv_core -llibtiff -llibjpeg -llibjasper -llibpng -lIlmImf -llibprotobuf -llibwebp -ltbb -lcpufeatures -ltegra_hal