Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. VideoCapture OpenCV Error?
Qt 6.11 is out! See what's new in the release blog

VideoCapture OpenCV Error?

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 1.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Helaly96
    wrote on last edited by Helaly96
    #1

    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 ?

    H 1 Reply Last reply
    0
    • H Helaly96

      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 ?

      H Offline
      H Offline
      Helaly96
      wrote on last edited by
      #2
      This post is deleted!
      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi and welcome to devnet,

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

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved