Important: Please read the Qt Code of Conduct -

Problem with OpenCV on Ubuntu

  • Hi,

    I want to add library Open CV to my qt project so in the pro file I added:

    QT       += core gui
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    TARGET = ClientApp
    TEMPLATE = app
    CONFIG += c++11 \
    INCLUDEPATH += -I/usr/local/include/opencv4
    LIBS += -L/usr/local/lib -lopencv_core -lopencv_imgcodecs -lopencv_highgui
    SOURCES += \
            main.cpp \
    HEADERS += \
    FORMS += \
    # Default rules for deployment.
    qnx: target.path = /tmp/$${TARGET}/bin
    else: unix:!android: target.path = /opt/$${TARGET}/bin
    !isEmpty(target.path): INSTALLS += target

    But when I try to include in mainwindow.h:

    #include <opencv4/opencv2/core/core.hpp>

    I get error :

    /usr/local/include/opencv4/opencv2/core/core.hpp:48: error: opencv2/core.hpp: No such file or directory
     #include "opencv2/core.hpp"

    I checked the core.hpp file in this path and it is. What could I do?

  • @Creatorczyk said in Problem with OpenCV on Ubuntu:

    #include <opencv4/opencv2/core/core.hpp>

    Remove opencv4 and try just #include <opencv2/core/core.hpp>
    Your *.pro file looks correct.

    What version of OCV do you have installed?

  • Lifetime Qt Champion


    @Creatorczyk said in Problem with OpenCV on Ubuntu:

    INCLUDEPATH += -I/usr/local/include/opencv4

    You are providing the include path up to opencv4. Either remove it here, or as @Pl45m4 remove it from your includes.

    Note that you do not need to add the -I with INCLUDEPATH.

  • @SGaist I removed -I from include and it's works. Thanks!

Log in to reply