opencv error: undefined reference to `cv::VideoCapture::VideoCapture()'



  • I try to use opencv3.2 with qt5.7,but I always get those erros:
    /home/hunter/cameraTt/main.cpp:17: error: undefined reference to cv::VideoCapture::open(int)' /home/hunter/cameraTt/main.cpp:18: error: undefined reference tocv::VideoCapture::isOpened() const'
    /home/hunter/cameraTt/main.cpp:20: error: undefined reference to cv::VideoCapture::get(int) const' /home/hunter/cameraTt/main.cpp:22: error: undefined reference tocv::VideoCapture::operator>>(cv::Mat&)'
    /home/hunter/cameraTt/main.cpp:24: error: undefined reference to `cv::VideoWriter::VideoWriter()'
    ....
    .pro

    INCLUDEPATH += /usr/local/include/opencv2

    LIBS += /usr/local/lib/libopencv_shape.so \

          /usr/local/lib/libopencv_videoio.so \
    

    main.cpp

    #include "mainwindow.h"
    #include <QApplication>
    //#include<cv.h>
    #include<QTimer>
    #include<QPixmap>
    #include <opencv2/core/core.hpp>
    #include <opencv2/highgui/highgui.hpp>
    #include <opencv2/imgproc/imgproc.hpp>
    //using namespace cv;
    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    MainWindow w;
    w.show();

    cv::VideoCapture m_cap;
    m_cap.open(0);
    assert(m_cap.isOpened());
    
    int rate = m_cap.get(CV_CAP_PROP_FPS);
    cv::Mat frame;
    m_cap>>frame;
    
    cv::VideoWriter videowriter;
    videowriter.open("test.wmv",CV_FOURCC('W','M','V','2'),30,cv::Size(frame.cols,frame.rows));
    assert(videowriter.isOpened());
    
    char keycode;
    while ((keycode = cvWaitKey(30))) {
        if (keycode == 27) {
            break;
        }
        if (!m_cap.grab()) {
            break;
        }
        m_cap>>frame;
        videowriter<<frame;
    }
    videowriter.release();
    
    return a.exec();
    

    }


  • Qt Champions 2018

    HI @_hunter,

    LIBS += /usr/local/lib/libopencv_shape.so
    /usr/local/lib/libopencv_videoio.so

    Please change the linker lines to this,

    LIBS += -L/usr/local/lib -lopencv_shape -lopencv_videoio

    and try again.

    If it does not work, please prove the linker command line from the compile log.

    Regards



  • @aha_1980 said in opencv error: undefined reference to `cv::VideoCapture::VideoCapture()':

    compile log

    sorry,i do not know the location of compile log.I did what you sugget and here are the new errors:
    :-1: error: main.o: undefined reference to symbol '_ZN2cv6String10deallocateEv'
    /usr/local/lib/libopencv_core.so.3.2:-1: error: error adding symbols: DSO missing from command line
    :-1: error: collect2: error: ld returned 1 exit status



  • @aha_1980 thank you with your help,i solved this error


  • Qt Champions 2018

    @_hunter

    Glad it worked. So please close this topic as SOLVED. Thanks.



  • @_hunter I'm also getting the same error.. How you solved it. Can you please help me?


  • Qt Champions 2018

    @SuganyaSP Did you do what @aha_1980 suggested?


Log in to reply
 

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