How to install openCv in Qt



  • Hello,

    I am looking for context in regards to getting openCv essentially in my application to work. I have managed to do what I would like to accomplish but am taking a learning curve and diving into Qt for lots of obvious reasons and at this point I just am learning and navigating so far what I have found though is to put (see below) into the .pro file but nothing is happening or suggesting when [example ] #include<opencv>

    LIBS += -L/usr/local/lib
    -lopencv_core /
    -lopencv_imgproc /
    -lopencv_features2d/
    -lopencv_highgui


  • Lifetime Qt Champion

    Hi,

    You must use backslashes when doing multiline assignments like this one.



  • Im using he backslashes just essentially replaced what I had above ****** LIBS += -L\usr\local\lib
    -lopencv_core
    -lopencv_imgproc
    -lopencv_features2d
    -lopencv_highgui

    But still am having difficulties is there something I'm missing here? I am using Mac OSX... and have accomplished this is Xcode but just doesn't seem to be working is there anything else to configure etc?


  • Lifetime Qt Champion

    I meant: use backslashes when marking a new line. For the paths themselves use forward slashes.

    What error are you getting ?



  • @Trav said:

    LIBS += -L/usr/local/lib
    -lopencv_core /
    -lopencv_imgproc /
    -lopencv_features2d/
    -lopencv_highgui

    2 days ago

    sorry for the wait... all I'm getting is opencv.cpp not found... is there solid documentation somewhere on this subject? thank you


  • Lifetime Qt Champion

    opencv.cpp not found ? Where's that file coming from ?

    Not knowing what your current error relates to I can't give you any recommendation.



  • The actual file itself 'openCV ' is located on my desktop... I made a file 'build' inside the folder and then 'lib' where all the files are located ; highgui etc. Is there a crucial step I missed here ? I mean I downloaded openCV installed Cmake by following a tutorial and installed this perfectly fine in Xcode.. But since moving to Qt I have not been able to get the same results.



  • Could you please tell me in your case how would you do this if you were using Mac assuming we have Qt installed and openCV...


  • Lifetime Qt Champion

    There are several possibilities.

    You can use pkg-config or do it like you do currently and provide the INCLUDEPATH and LIBS with the adequate data.

    Can you share your complete .pro file ? From the bits you've given, one time you have used the wrong line ending char and the other you are complete missing it.

    Example:

    LIBS += \
        -L/usr/local/lib \
        -lopencv_core \
        -lopencv_highgui
    
    INCLUDEPATH += \
        /usr/local/include 
    

    You should also post the exact error you are having.



  • Yes please see bottom for code. If it at all has changed I have been modifying it and tuning it according to different tutorials to see if it'll work etc. But essentially the end result is the same ERROR: opencv.h not found' when using ' #include <opencv.h> or something similar; highgui, core ...

    #-------------------------------------------------

    Project created by QtCreator 2016-05-15T23:16:25

    #-------------------------------------------------

    QT += core gui

    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

    TARGET = cam
    TEMPLATE = app

    // new
    QT += core
    QT -= gui

    TARGET = RP_openCV_01
    CONFIG += console
    CONFIG -= app_bundle

    TEMPLATE = app

    SOURCES += main.cpp
    mainwindow.cpp

    LIBS += -L/opt/local/lib
    -lopencv_highgui.3.1.0
    -lopencv_core.3.1.0

    INCLUDEPATH += /opt/local/include

    HEADERS += mainwindow.h

    FORMS += mainwindow.ui



  • Only error is the error that is indicating the header files are not found " OPENCV.H not found!'

    QT += core gui

    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

    TARGET = cam
    TEMPLATE = app

    // new
    QT += core
    QT -= gui

    TARGET = RP_openCV_01
    CONFIG += console
    CONFIG -= app_bundle

    TEMPLATE = app

    SOURCES += main.cpp
    mainwindow.cpp

    LIBS += -L/opt/local/lib
    -lopencv_highgui.3.1.0
    -lopencv_core.3.1.0

    INCLUDEPATH += /opt/local/include

    HEADERS += mainwindow.h

    FORMS += mainwindow.ui


  • Lifetime Qt Champion

    Shouldn't it be #include <opencv2/opencv.hpp> ?



  • Sorry, yes; I have used the #include <opencv2/opencv.hpp> and the error I stated above is still valid


  • Lifetime Qt Champion

    Do you mean the opencv.h not found error ?



  • Hey, thanks for your help I actually got it and have reproduced the desired outcome... essentially what happened because I am new to Qt & OpenCV etc. It seems I have placed the code before Sources' in the project.pro file which produced the errors... I did this before as well I don't quite understand why it decides to work now but did not before? but essentially I'm good :) thanks for support


  • Lifetime Qt Champion

    Good !

    In that case, please mark the thread as solved using the "Topic Tool" button so that other forum users may know a solution has been found :)


Log in to reply
 

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