Opencv in Android



  • I'm trying to use the openCV libraries in a android application but I'm having problems to do this, someone knows a way to do this work?

    Edit: I'm using ubuntu 14.04, Qt 5.7 and OpenCV 3.0.


  • Lifetime Qt Champion

    Hi,

    That's a bit vague. What did you try ? What errors are you getting ? Can you make a "pure" OpenCV sample application run on your Android device ?



  • I just followed this tutorial but when a try it I'm still not able to include OpenCV libraries in my project and I receive the message "No such file or directory"


  • Lifetime Qt Champion

    Can you share you .pro file and what file isn't found ?



  • Sure, actually my .pro file is

    TEMPLATE = app
    
    QT += qml quick
    CONFIG += c++11
    
    SOURCES += main.cpp \
        imagerecog.cpp
    
    INCLUDEPATH += /usr/local/include/opencv
    LIBS += -L/usr/local/lib -lopencv_core -lopencv_imgcodecs -lopencv_highgui
    
    RESOURCES += qml.qrc
    
    
    # Additional import path used to resolve QML modules in Qt Creator's code model
    QML_IMPORT_PATH =
    
    # Default rules for deployment.
    include(deployment.pri)
    
    DISTFILES += \
        android/AndroidManifest.xml \
        android/gradle/wrapper/gradle-wrapper.jar \
        android/gradlew \
        android/res/values/libs.xml \
        android/build.gradle \
        android/gradle/wrapper/gradle-wrapper.properties \
        android/gradlew.bat
    
    ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android
    
    HEADERS += \
        imagerecog.h
    
    

    And the error happens when I try to include the OpenCV libs

    Ex: #include <opencv2/opencv.hpp>

    And its not found


  • Lifetime Qt Champion

    Shouldn't that rather be INCLUDEPATH += /usr/local/include/ ?

    IIRC, the opencv and opencv2 folder are in the same directory.



  • When I try this I can include the libs but in build I receive this errors
    this erros:
    :-1: error: error: cannot find -lopencv_core
    :-1: error: error: cannot find -lopencv_imgcodecs
    :-1: error: error: cannot find -lopencv_highgui
    :-1: error: collect2: error: ld returned 1 exit status


  • Lifetime Qt Champion

    What are the exact name of the libraries you have there ?



  • In the usr/local/lib folder -> libopencv_core.so, libopencv_highgui.so, libopencv_imgcodecs.so;


  • Lifetime Qt Champion

    No version number ?


  • Qt Champions 2016

    @OliveiraNT said:

    In the usr/local/lib folder -> libopencv_core.so, libopencv_highgui.so, libopencv_imgcodecs.so;

    Are you really using opencv for Android? The prebuilt package should only contains .a file for the library above.



  • @benlau and @SGaist tanks for the help, I didn't know there is an openCV just for android.
    I solved my problem adding the openCV sdk for android at my project with this:

    TEMPLATE = app
    
    QT += qml quick
    CONFIG += c++11
    
    SOURCES += main.cpp \
        processaimagem.cpp \
        provedorimagem.cpp
    
    INCLUDEPATH += /home/gpca/Qt/OpenCV-android-sdk/sdk/native/jni/include
    OPENCV3RDPARTYLIBS = /home/gpca/Qt/OpenCV-android-sdk/sdk/native/3rdparty/libs/armeabi-v7a
    OPENCVNATIVELIBS = /home/gpca/Qt/OpenCV-android-sdk/sdk/native/libs/armeabi-v7a
    LIBS += $$OPENCV3RDPARTYLIBS/liblibtiff.a
    $$OPENCV3RDPARTYLIBS/liblibjpeg.a
    $$OPENCV3RDPARTYLIBS/liblibjasper.a
    $$OPENCV3RDPARTYLIBS/liblibpng.a
    $$OPENCV3RDPARTYLIBS/libtbb.a
    $$OPENCV3RDPARTYLIBS/libIlmImf.a
    LIBS += $$OPENCVNATIVELIBS/libopencv_core.a
    $$OPENCVNATIVELIBS/libopencv_androidcamera.a
    $$OPENCVNATIVELIBS/libopencv_flann.a
    $$OPENCVNATIVELIBS/libopencv_imgproc.a
    $$OPENCVNATIVELIBS/libopencv_highgui.a
    $$OPENCVNATIVELIBS/libopencv_features2d.a
    $$OPENCVNATIVELIBS/libopencv_calib3d.a
    $$OPENCVNATIVELIBS/libopencv_ml.a
    $$OPENCVNATIVELIBS/libopencv_objdetect.a
    $$OPENCVNATIVELIBS/libopencv_photo.a
    $$OPENCVNATIVELIBS/libopencv_stitching.a
    $$OPENCVNATIVELIBS/libopencv_superres.a
    $$OPENCVNATIVELIBS/libopencv_ts.a
    $$OPENCVNATIVELIBS/libopencv_video.a
    $$OPENCVNATIVELIBS/libopencv_videostab.a
    $$OPENCVNATIVELIBS/libopencv_java.so
    
    ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android-sources
    
    RESOURCES += qml.qrc
    
    
    # Additional import path used to resolve QML modules in Qt Creator's code model
    QML_IMPORT_PATH =
    
    # Default rules for deployment.
    include(deployment.pri)
    
    DISTFILES += \
        android/AndroidManifest.xml \
        android/gradle/wrapper/gradle-wrapper.jar \
        android/gradlew \
        android/res/values/libs.xml \
        android/build.gradle \
        android/gradle/wrapper/gradle-wrapper.properties \
        android/gradlew.bat
    
    ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android
    
    HEADERS += \
        processaimagem.h \
        provedorimagem.h
    
    

    Again, thank you both for the help.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.