Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/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
    2.4.9.1
    
    

    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.
    DEFINES += QT_DEPRECATED_WARNINGS
    
    # 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 += \
            main.cpp
    
    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 ( ! cap.read(frame) ) // cam might need some warmup
                    continue;
    
                // your processing goes here
    
                imshow("lalala",frame);
                if ( waitKey(10)==27 )
                    break;
            }
    
        return a.exec();
    }
    
    

    i followed this link and reached this point

    https://forum.qt.io/topic/92848/opencv-error-undefined-reference-to-cv-videocapture-videocapture

    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