Important: Please read the Qt Code of Conduct -

VideoCapture OpenCV Error?

  • i installed opencv on Ubuntu and tested it outside of qt with a simple C++ script, and it worked just fine.

    My compiler is GCC 5.3.1

    now i want to use in QT widgets application.

    pkg-config --modversion opencv

    above is the version of the Opencv installed.

    here is the .pro file

    QT += core gui network
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    TARGET = untitled
    TEMPLATE = app
    # The following define makes your compiler emit warnings if you use
    # any feature of Qt which has been marked as deprecated (the exact warnings
    # depend on your compiler). Please consult the documentation of the
    # deprecated API in order to know how to port your code away from it.
    # You can also make your code fail to compile if you use deprecated APIs.
    # In order to do so, uncomment the following line.
    # You can also select to disable deprecated APIs only up to a certain version of Qt.
    #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
    CONFIG += c++11
    SOURCES += \
    HEADERS +=
    FORMS +=
    INCLUDEPATH += /usr/local/include/opencv
    LIBS += -L/usr/local/lib -lopencv_shape -lopencv_videoio -lopencv_highgui
    # Default rules for deployment.
    qnx: target.path = /tmp/$${TARGET}/bin
    else: unix:!android: target.path = /opt/$${TARGET}/bin
    !isEmpty(target.path): INSTALLS += target

    here is the main.cpp file

    #include "mainwindow.h"
    #include <QApplication>
    #include "opencv2/core/core.hpp"
    #include "opencv2/imgproc/imgproc.hpp"
    #include "opencv2/highgui/highgui.hpp"
    #include "opencv2/video/video.hpp"
    using namespace cv;
    int main(int argc, char *argv[])
        QApplication a(argc, argv);
        VideoCapture cap(0); // get first cam
            while( cap.isOpened() )
                Mat frame;
                if ( ! ) // cam might need some warmup
                // your processing goes here
                if ( waitKey(10)==27 )
        return a.exec();

    i followed this link and reached this point

    and reached this compiler error

    0_1539577649502_Screenshot from 2018-10-15 06-25-16.png

    anyone know the issue ?

  • This post is deleted!

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    You can use pkg-config with qmake. See if it helps with OpenCV.

Log in to reply