Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Errors: undefined reference to cv::VideoCapture::VideoCapture()
Forum Updated to NodeBB v4.3 + New Features

Errors: undefined reference to cv::VideoCapture::VideoCapture()

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
25 Posts 6 Posters 3.4k Views 2 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.
  • JonBJ JonB

    @Pl45m4
    Except that OP shows that certain items are missing from the link... :)

    And now I see the OP's latest post shows linking with different libraries from the original post, so I hand the OP over to you... :)

    Pl45m4P Offline
    Pl45m4P Offline
    Pl45m4
    wrote on last edited by Pl45m4
    #9

    @JonB said in Errors: undefined reference to cv::VideoCapture::VideoCapture():

    Except that OP shows that certain items are missing from the link... :)

    Yeah, but linking opencv_worldXXX is not the issue here ;-)

    So @Ronel_qtmaster wasn't wrong with his comment.

    As:

    @Arev said in Errors: undefined reference to cv::VideoCapture::VideoCapture():

    I compile it with mingw32

    and:

    -L$$PWD/opencv/build/x64/vc16/lib/ -lopencv_world490

    MinGW x32 vs. VC x64

    That's not going to work ;-)

    Edit:

    @Arev said in Errors: undefined reference to cv::VideoCapture::VideoCapture():

    I modified it and downloaded the opencv build for mingw from this repository

    /x64/mingw/lib/

    Then you still have to use MinGWx64

    Btw:
    Please don't post code as picture. Post as text using the code tags (</> button)


    If debugging is the process of removing software bugs, then programming must be the process of putting them in.

    ~E. W. Dijkstra

    A 1 Reply Last reply
    1
    • A Arev

      @JonB
      I modified it and downloaded the opencv build for mingw from this repository

      https://github.com/huihut/OpenCV-MinGW-Build/tree/OpenCV-4.5.5-x64

      95a9f69b-bede-43f9-bf12-ef6a89524861-image.png

      and I added all libs

      Ronel_qtmasterR Offline
      Ronel_qtmasterR Offline
      Ronel_qtmaster
      wrote on last edited by
      #10

      @Arev First of all, you cannot download libraries of opencv 4.5.5 and use it with QT5.9.9 because there are uncompatible due to the mingw version of Qt5.9.

      Moreover, are you sure that these built opencv librairies where to use with Qt5.9?

      Again, you should instead download the sources of opencv, install cmake and build opencv.During the build you can insert your the qt version used for that opencv.

      PS: cmake is only for building the sources of opencv in other to make them usable with your Qt version, Not to build your project

      1 Reply Last reply
      0
      • Pl45m4P Pl45m4

        @JonB said in Errors: undefined reference to cv::VideoCapture::VideoCapture():

        Except that OP shows that certain items are missing from the link... :)

        Yeah, but linking opencv_worldXXX is not the issue here ;-)

        So @Ronel_qtmaster wasn't wrong with his comment.

        As:

        @Arev said in Errors: undefined reference to cv::VideoCapture::VideoCapture():

        I compile it with mingw32

        and:

        -L$$PWD/opencv/build/x64/vc16/lib/ -lopencv_world490

        MinGW x32 vs. VC x64

        That's not going to work ;-)

        Edit:

        @Arev said in Errors: undefined reference to cv::VideoCapture::VideoCapture():

        I modified it and downloaded the opencv build for mingw from this repository

        /x64/mingw/lib/

        Then you still have to use MinGWx64

        Btw:
        Please don't post code as picture. Post as text using the code tags (</> button)

        A Offline
        A Offline
        Arev
        wrote on last edited by
        #11

        @Pl45m4
        Oh, I download opencv build for x86 and errors fixed
        But now my program doesn't open, I think the problem is in this line

        static cv::VideoCapture cap;
        
        jsulmJ 2 Replies Last reply
        0
        • A Arev

          @Pl45m4
          Oh, I download opencv build for x86 and errors fixed
          But now my program doesn't open, I think the problem is in this line

          static cv::VideoCapture cap;
          
          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #12

          @Arev said in Errors: undefined reference to cv::VideoCapture::VideoCapture():

          But now my program doesn't open

          Then use debugger...

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          A 1 Reply Last reply
          0
          • jsulmJ jsulm

            @Arev said in Errors: undefined reference to cv::VideoCapture::VideoCapture():

            But now my program doesn't open

            Then use debugger...

            A Offline
            A Offline
            Arev
            wrote on last edited by
            #13

            @jsulm

            I try it and I get the error:
            Executable failed: During startup program exited with code 0xc0000135.

            jsulmJ 1 Reply Last reply
            0
            • A Arev

              @Pl45m4
              Oh, I download opencv build for x86 and errors fixed
              But now my program doesn't open, I think the problem is in this line

              static cv::VideoCapture cap;
              
              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #14

              @Arev said in Errors: undefined reference to cv::VideoCapture::VideoCapture():

              static cv::VideoCapture cap

              Does it work without this line?
              Why is cap static?

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              A 1 Reply Last reply
              0
              • jsulmJ jsulm

                @Arev said in Errors: undefined reference to cv::VideoCapture::VideoCapture():

                static cv::VideoCapture cap

                Does it work without this line?
                Why is cap static?

                A Offline
                A Offline
                Arev
                wrote on last edited by
                #15

                @jsulm

                cv::VideoCapture:
                

                This is a class from the OpenCV library used for capturing video from camera devices or video files. It provides methods to open, read, and manage video streams.
                By declaring cap as static, it's accessible across all instances of the class, and there will be only one instance of it throughout the program execution.

                jsulmJ 1 Reply Last reply
                0
                • A Arev

                  @jsulm

                  cv::VideoCapture:
                  

                  This is a class from the OpenCV library used for capturing video from camera devices or video files. It provides methods to open, read, and manage video streams.
                  By declaring cap as static, it's accessible across all instances of the class, and there will be only one instance of it throughout the program execution.

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #16

                  @Arev I did not ask what it is, I asked whether your app starts if this line is not there.

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  A 1 Reply Last reply
                  0
                  • jsulmJ jsulm

                    @Arev I did not ask what it is, I asked whether your app starts if this line is not there.

                    A Offline
                    A Offline
                    Arev
                    wrote on last edited by
                    #17

                    @jsulm

                    Oh sorry, I created another test app and added that line that nothing in the app depended on and it didn't work and didn't cause any problems, but without that line the app works.

                    1 Reply Last reply
                    0
                    • A Arev

                      @jsulm

                      I try it and I get the error:
                      Executable failed: During startup program exited with code 0xc0000135.

                      jsulmJ Offline
                      jsulmJ Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on last edited by
                      #18

                      @Arev said in Errors: undefined reference to cv::VideoCapture::VideoCapture():

                      0xc0000135

                      This error code means: STATUS_DLL_NOT_FOUND
                      Looks like the cv libs are not found when starting your app. How do you start it? From QtCreator?

                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                      A 1 Reply Last reply
                      1
                      • jsulmJ jsulm

                        @Arev said in Errors: undefined reference to cv::VideoCapture::VideoCapture():

                        0xc0000135

                        This error code means: STATUS_DLL_NOT_FOUND
                        Looks like the cv libs are not found when starting your app. How do you start it? From QtCreator?

                        A Offline
                        A Offline
                        Arev
                        wrote on last edited by
                        #19

                        @jsulm

                        I can share code
                        This is my .pro

                        QT += quick
                        
                        CONFIG += c++11
                        QT_DISABLE_DEPRECATED_BEFORE=0x060000  
                        
                        SOURCES += \
                                main.cpp \
                                opencvimageprovider.cpp \
                                videostreamer.cpp
                        
                        RESOURCES += qml.qrc
                        
                        QML_IMPORT_PATH =
                        
                        QML_DESIGNER_IMPORT_PATH =
                        
                        qnx: target.path = /tmp/$${TARGET}/bin
                        else: unix:!android: target.path = /opt/$${TARGET}/bin
                        !isEmpty(target.path): INSTALLS += target
                        
                        HEADERS += \
                            opencvimageprovider.h \
                            videostreamer.h \
                        
                        win32: LIBS += -L$$PWD/OpenCV-MinGW-Build-OpenCV-4.5.0-with-contrib/x64/mingw/lib/ -llibopencv_videoio450.dll
                        win32: LIBS += -L$$PWD/OpenCV-MinGW-Build-OpenCV-4.5.0-with-contrib/x64/mingw/lib/-llibopencv_calib3d450.dll
                        win32: LIBS += -L$$PWD/OpenCV-MinGW-Build-OpenCV-4.5.0-with-contrib/x64/mingw/lib/-llibopencv_core450.dll
                        win32: LIBS += -L$$PWD/OpenCV-MinGW-Build-OpenCV-4.5.0-with-contrib/x64/mingw/lib/-llibopencv_dnn450.dll
                        win32: LIBS += -L$$PWD/OpenCV-MinGW-Build-OpenCV-4.5.0-with-contrib/x64/mingw/lib/-llibopencv_features2d450.dll
                        win32: LIBS += -L$$PWD/OpenCV-MinGW-Build-OpenCV-4.5.0-with-contrib/x64/mingw/lib/-llibopencv_flann450.dll
                        win32: LIBS += -L$$PWD/OpenCV-MinGW-Build-OpenCV-4.5.0-with-contrib/x64/mingw/lib/-llibopencv_gapi450.dll
                        win32: LIBS += -L$$PWD/OpenCV-MinGW-Build-OpenCV-4.5.0-with-contrib/x64/mingw/lib/-llibopencv_highgui450.dll
                        win32: LIBS += -L$$PWD/OpenCV-MinGW-Build-OpenCV-4.5.0-with-contrib/x64/mingw/lib/-llibopencv_imgcodecs450.dll
                        win32: LIBS += -L$$PWD/OpenCV-MinGW-Build-OpenCV-4.5.0-with-contrib/x64/mingw/lib/-llibopencv_imgproc450.dll
                        win32: LIBS += -L$$PWD/OpenCV-MinGW-Build-OpenCV-4.5.0-with-contrib/x64/mingw/lib/-llibopencv_ml450.dll
                        win32: LIBS += -L$$PWD/OpenCV-MinGW-Build-OpenCV-4.5.0-with-contrib/x64/mingw/lib/-llibopencv_objdetect450.dll
                        win32: LIBS += -L$$PWD/OpenCV-MinGW-Build-OpenCV-4.5.0-with-contrib/x64/mingw/lib/-llibopencv_stitching450.dll
                        win32: LIBS += -L$$PWD/OpenCV-MinGW-Build-OpenCV-4.5.0-with-contrib/x64/mingw/lib/-llibopencv_photo450.dll
                        win32: LIBS += -L$$PWD/OpenCV-MinGW-Build-OpenCV-4.5.0-with-contrib/x64/mingw/lib/-llibopencv_video450.dll
                        win32: LIBS += -L$$PWD/OpenCV-MinGW-Build-OpenCV-4.5.0-with-contrib/x64/mingw/lib/-llibopencv_videoio450.dll
                        
                        INCLUDEPATH += $$PWD/OpenCV-MinGW-Build-OpenCV-4.5.0-with-contrib/include
                        DEPENDPATH += $$PWD/OpenCV-MinGW-Build-OpenCV-4.5.0-with-contrib/include
                        
                        win32: LIBS += -L$$PWD/OpenCV-MinGW-Build-OpenCV-4.5.0-with-contrib/x64/mingw/lib/ -llibopencv_core450.dll
                        
                        INCLUDEPATH += $$PWD/OpenCV-MinGW-Build-OpenCV-4.5.0-with-contrib/include
                        DEPENDPATH += $$PWD/OpenCV-MinGW-Build-OpenCV-4.5.0-with-contrib/include
                        
                        
                        

                        Main.cpp

                        #include <QGuiApplication>
                        #include <QQmlApplicationEngine>
                        #include "opencvimageprovider.h"
                        #include "videostreamer.h"
                        #include <QQmlContext>
                        
                        int main(int argc, char *argv[])
                        {
                            QGuiApplication app(argc, argv);
                        
                            QQmlApplicationEngine engine;
                        
                            qRegisterMetaType<cv::Mat>("cv::Mat");
                        
                            VideoStreamer videoStreamer;
                        
                            OpencvImageProvider *liveImageProvider(new OpencvImageProvider);
                        
                            engine.rootContext()->setContextProperty("VideoStreamer",&videoStreamer);
                            engine.rootContext()->setContextProperty("liveImageProvider",liveImageProvider);
                        
                            engine.addImageProvider("live",liveImageProvider);
                        
                            const QUrl url(QStringLiteral("qrc:/main.qml"));
                        
                            engine.load(url);
                        
                            QObject::connect(&videoStreamer,&VideoStreamer::newImage,liveImageProvider,&OpencvImageProvider::updateImage);
                        
                            return app.exec();
                        }
                        

                        VideoStreamer.h

                        #ifndef VIDEOSTREAMER_H
                        #define VIDEOSTREAMER_H
                        
                        #include <QObject>
                        #include <QTimer>
                        #include <OpenCV-MinGW-Build-OpenCV-4.5.0-with-contrib/include/opencv2/opencv.hpp>
                        #include <QImage>
                        #include <iostream>
                        #include <QThread>
                        
                        
                        static cv::VideoCapture cap;
                        
                        
                        class VideoStreamer: public QObject
                        {
                            Q_OBJECT
                        public:
                            VideoStreamer();
                            ~VideoStreamer();
                        
                        public:
                            void streamVideo();
                            QThread* threadStreamer = new QThread();
                            void catchFrame(cv::Mat emittedFrame);
                        
                        public slots:
                            void openVideoCamera(QString path);
                        
                            void streamerThreadSlot();
                        
                        private:
                        
                            cv::Mat frame;
                            QTimer tUpdate;
                        
                        signals:
                            void newImage(QImage &);
                        
                            void emitThreadImage(cv::Mat frameThread);
                        };
                        
                        #endif // VIDEOSTREAMER_H
                        
                        

                        VideoStreamer.cpp

                        #include "videostreamer.h"
                        
                        VideoStreamer::VideoStreamer()
                        {
                            connect(&tUpdate,&QTimer::timeout,this,&VideoStreamer::streamVideo);
                        
                        }
                        
                        VideoStreamer::~VideoStreamer()
                        {
                            cap.release();
                            tUpdate.stop();
                            threadStreamer->requestInterruption();
                        }
                        
                        void VideoStreamer::streamVideo()
                        {
                        
                            if(frame.data)
                            {
                                QImage img = QImage(frame.data,frame.cols,frame.rows,QImage::Format_RGB888).rgbSwapped();
                                emit newImage(img);
                            }
                        }
                        
                        void VideoStreamer::catchFrame(cv::Mat emittedFrame)
                        {
                            frame = emittedFrame;
                        }
                        
                        void VideoStreamer::openVideoCamera(QString path)
                        {
                            if(path.length() == 1)
                            cap.open(path.toInt());
                            else
                            cap.open(path.toStdString());
                        
                            VideoStreamer* worker = new VideoStreamer();
                            worker->moveToThread(threadStreamer);
                            QObject::connect(threadStreamer,SIGNAL(started()),worker,SLOT(streamerThreadSlot()));
                            QObject::connect(worker,&VideoStreamer::emitThreadImage,this,&VideoStreamer::catchFrame);
                            threadStreamer->start();
                        
                            double fps = cap.get(cv::CAP_PROP_FPS);
                            tUpdate.start(1000/fps);
                        }
                        
                        void VideoStreamer::streamerThreadSlot()
                        {
                            cv::Mat tempFrame;
                        
                            while (1) {
                                cap>>tempFrame;
                                if(tempFrame.data)
                                    emit emitThreadImage(tempFrame);
                        
                                if(QThread::currentThread()->isInterruptionRequested())
                                {
                                    cap.release();
                                    return;
                                }
                        
                            }
                        }
                        
                        

                        OpencvImageProvider.h

                        #ifndef OPENCVIMAGEPROVIDER_H
                        #define OPENCVIMAGEPROVIDER_H
                        
                        
                        #include <QObject>
                        #include <QImage>
                        #include <QQuickImageProvider>
                        
                        class OpencvImageProvider : public QObject, public QQuickImageProvider
                        {
                            Q_OBJECT
                        public:
                            OpencvImageProvider(QObject *parent = nullptr);
                        
                            QImage requestImage(const QString &id, QSize *size, const QSize &requestedSize) override;
                        
                        public slots:
                            void updateImage(const QImage &image);
                        
                        signals:
                            void imageChanged();
                        
                        private:
                            QImage image;
                        };
                        
                        #endif // OPENCVIMAGEPROVIDER_H
                        

                        OpencvImageProvider.cpp

                        #include "opencvimageprovider.h"
                        
                        OpencvImageProvider::OpencvImageProvider(QObject *parent) : QObject(parent), QQuickImageProvider(QQuickImageProvider::Image)
                        {
                            image = QImage(200,200,QImage::Format_RGB32);
                            image.fill(QColor("black"));
                        }
                        
                        QImage OpencvImageProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize)
                        {
                            Q_UNUSED(id);
                        
                            if(size){
                                *size = image.size();
                            }
                        
                            if(requestedSize.width() > 0 && requestedSize.height() > 0) {
                                image = image.scaled(requestedSize.width(), requestedSize.height(), Qt::KeepAspectRatio);
                            }
                            return image;
                        }
                        
                        void OpencvImageProvider::updateImage(const QImage &image)
                        {
                            if(!image.isNull() && this->image != image) {
                                this->image = image;
                                emit imageChanged();
                            }
                        }
                        
                        
                        jsulmJ 1 Reply Last reply
                        0
                        • A Arev

                          @jsulm

                          I can share code
                          This is my .pro

                          QT += quick
                          
                          CONFIG += c++11
                          QT_DISABLE_DEPRECATED_BEFORE=0x060000  
                          
                          SOURCES += \
                                  main.cpp \
                                  opencvimageprovider.cpp \
                                  videostreamer.cpp
                          
                          RESOURCES += qml.qrc
                          
                          QML_IMPORT_PATH =
                          
                          QML_DESIGNER_IMPORT_PATH =
                          
                          qnx: target.path = /tmp/$${TARGET}/bin
                          else: unix:!android: target.path = /opt/$${TARGET}/bin
                          !isEmpty(target.path): INSTALLS += target
                          
                          HEADERS += \
                              opencvimageprovider.h \
                              videostreamer.h \
                          
                          win32: LIBS += -L$$PWD/OpenCV-MinGW-Build-OpenCV-4.5.0-with-contrib/x64/mingw/lib/ -llibopencv_videoio450.dll
                          win32: LIBS += -L$$PWD/OpenCV-MinGW-Build-OpenCV-4.5.0-with-contrib/x64/mingw/lib/-llibopencv_calib3d450.dll
                          win32: LIBS += -L$$PWD/OpenCV-MinGW-Build-OpenCV-4.5.0-with-contrib/x64/mingw/lib/-llibopencv_core450.dll
                          win32: LIBS += -L$$PWD/OpenCV-MinGW-Build-OpenCV-4.5.0-with-contrib/x64/mingw/lib/-llibopencv_dnn450.dll
                          win32: LIBS += -L$$PWD/OpenCV-MinGW-Build-OpenCV-4.5.0-with-contrib/x64/mingw/lib/-llibopencv_features2d450.dll
                          win32: LIBS += -L$$PWD/OpenCV-MinGW-Build-OpenCV-4.5.0-with-contrib/x64/mingw/lib/-llibopencv_flann450.dll
                          win32: LIBS += -L$$PWD/OpenCV-MinGW-Build-OpenCV-4.5.0-with-contrib/x64/mingw/lib/-llibopencv_gapi450.dll
                          win32: LIBS += -L$$PWD/OpenCV-MinGW-Build-OpenCV-4.5.0-with-contrib/x64/mingw/lib/-llibopencv_highgui450.dll
                          win32: LIBS += -L$$PWD/OpenCV-MinGW-Build-OpenCV-4.5.0-with-contrib/x64/mingw/lib/-llibopencv_imgcodecs450.dll
                          win32: LIBS += -L$$PWD/OpenCV-MinGW-Build-OpenCV-4.5.0-with-contrib/x64/mingw/lib/-llibopencv_imgproc450.dll
                          win32: LIBS += -L$$PWD/OpenCV-MinGW-Build-OpenCV-4.5.0-with-contrib/x64/mingw/lib/-llibopencv_ml450.dll
                          win32: LIBS += -L$$PWD/OpenCV-MinGW-Build-OpenCV-4.5.0-with-contrib/x64/mingw/lib/-llibopencv_objdetect450.dll
                          win32: LIBS += -L$$PWD/OpenCV-MinGW-Build-OpenCV-4.5.0-with-contrib/x64/mingw/lib/-llibopencv_stitching450.dll
                          win32: LIBS += -L$$PWD/OpenCV-MinGW-Build-OpenCV-4.5.0-with-contrib/x64/mingw/lib/-llibopencv_photo450.dll
                          win32: LIBS += -L$$PWD/OpenCV-MinGW-Build-OpenCV-4.5.0-with-contrib/x64/mingw/lib/-llibopencv_video450.dll
                          win32: LIBS += -L$$PWD/OpenCV-MinGW-Build-OpenCV-4.5.0-with-contrib/x64/mingw/lib/-llibopencv_videoio450.dll
                          
                          INCLUDEPATH += $$PWD/OpenCV-MinGW-Build-OpenCV-4.5.0-with-contrib/include
                          DEPENDPATH += $$PWD/OpenCV-MinGW-Build-OpenCV-4.5.0-with-contrib/include
                          
                          win32: LIBS += -L$$PWD/OpenCV-MinGW-Build-OpenCV-4.5.0-with-contrib/x64/mingw/lib/ -llibopencv_core450.dll
                          
                          INCLUDEPATH += $$PWD/OpenCV-MinGW-Build-OpenCV-4.5.0-with-contrib/include
                          DEPENDPATH += $$PWD/OpenCV-MinGW-Build-OpenCV-4.5.0-with-contrib/include
                          
                          
                          

                          Main.cpp

                          #include <QGuiApplication>
                          #include <QQmlApplicationEngine>
                          #include "opencvimageprovider.h"
                          #include "videostreamer.h"
                          #include <QQmlContext>
                          
                          int main(int argc, char *argv[])
                          {
                              QGuiApplication app(argc, argv);
                          
                              QQmlApplicationEngine engine;
                          
                              qRegisterMetaType<cv::Mat>("cv::Mat");
                          
                              VideoStreamer videoStreamer;
                          
                              OpencvImageProvider *liveImageProvider(new OpencvImageProvider);
                          
                              engine.rootContext()->setContextProperty("VideoStreamer",&videoStreamer);
                              engine.rootContext()->setContextProperty("liveImageProvider",liveImageProvider);
                          
                              engine.addImageProvider("live",liveImageProvider);
                          
                              const QUrl url(QStringLiteral("qrc:/main.qml"));
                          
                              engine.load(url);
                          
                              QObject::connect(&videoStreamer,&VideoStreamer::newImage,liveImageProvider,&OpencvImageProvider::updateImage);
                          
                              return app.exec();
                          }
                          

                          VideoStreamer.h

                          #ifndef VIDEOSTREAMER_H
                          #define VIDEOSTREAMER_H
                          
                          #include <QObject>
                          #include <QTimer>
                          #include <OpenCV-MinGW-Build-OpenCV-4.5.0-with-contrib/include/opencv2/opencv.hpp>
                          #include <QImage>
                          #include <iostream>
                          #include <QThread>
                          
                          
                          static cv::VideoCapture cap;
                          
                          
                          class VideoStreamer: public QObject
                          {
                              Q_OBJECT
                          public:
                              VideoStreamer();
                              ~VideoStreamer();
                          
                          public:
                              void streamVideo();
                              QThread* threadStreamer = new QThread();
                              void catchFrame(cv::Mat emittedFrame);
                          
                          public slots:
                              void openVideoCamera(QString path);
                          
                              void streamerThreadSlot();
                          
                          private:
                          
                              cv::Mat frame;
                              QTimer tUpdate;
                          
                          signals:
                              void newImage(QImage &);
                          
                              void emitThreadImage(cv::Mat frameThread);
                          };
                          
                          #endif // VIDEOSTREAMER_H
                          
                          

                          VideoStreamer.cpp

                          #include "videostreamer.h"
                          
                          VideoStreamer::VideoStreamer()
                          {
                              connect(&tUpdate,&QTimer::timeout,this,&VideoStreamer::streamVideo);
                          
                          }
                          
                          VideoStreamer::~VideoStreamer()
                          {
                              cap.release();
                              tUpdate.stop();
                              threadStreamer->requestInterruption();
                          }
                          
                          void VideoStreamer::streamVideo()
                          {
                          
                              if(frame.data)
                              {
                                  QImage img = QImage(frame.data,frame.cols,frame.rows,QImage::Format_RGB888).rgbSwapped();
                                  emit newImage(img);
                              }
                          }
                          
                          void VideoStreamer::catchFrame(cv::Mat emittedFrame)
                          {
                              frame = emittedFrame;
                          }
                          
                          void VideoStreamer::openVideoCamera(QString path)
                          {
                              if(path.length() == 1)
                              cap.open(path.toInt());
                              else
                              cap.open(path.toStdString());
                          
                              VideoStreamer* worker = new VideoStreamer();
                              worker->moveToThread(threadStreamer);
                              QObject::connect(threadStreamer,SIGNAL(started()),worker,SLOT(streamerThreadSlot()));
                              QObject::connect(worker,&VideoStreamer::emitThreadImage,this,&VideoStreamer::catchFrame);
                              threadStreamer->start();
                          
                              double fps = cap.get(cv::CAP_PROP_FPS);
                              tUpdate.start(1000/fps);
                          }
                          
                          void VideoStreamer::streamerThreadSlot()
                          {
                              cv::Mat tempFrame;
                          
                              while (1) {
                                  cap>>tempFrame;
                                  if(tempFrame.data)
                                      emit emitThreadImage(tempFrame);
                          
                                  if(QThread::currentThread()->isInterruptionRequested())
                                  {
                                      cap.release();
                                      return;
                                  }
                          
                              }
                          }
                          
                          

                          OpencvImageProvider.h

                          #ifndef OPENCVIMAGEPROVIDER_H
                          #define OPENCVIMAGEPROVIDER_H
                          
                          
                          #include <QObject>
                          #include <QImage>
                          #include <QQuickImageProvider>
                          
                          class OpencvImageProvider : public QObject, public QQuickImageProvider
                          {
                              Q_OBJECT
                          public:
                              OpencvImageProvider(QObject *parent = nullptr);
                          
                              QImage requestImage(const QString &id, QSize *size, const QSize &requestedSize) override;
                          
                          public slots:
                              void updateImage(const QImage &image);
                          
                          signals:
                              void imageChanged();
                          
                          private:
                              QImage image;
                          };
                          
                          #endif // OPENCVIMAGEPROVIDER_H
                          

                          OpencvImageProvider.cpp

                          #include "opencvimageprovider.h"
                          
                          OpencvImageProvider::OpencvImageProvider(QObject *parent) : QObject(parent), QQuickImageProvider(QQuickImageProvider::Image)
                          {
                              image = QImage(200,200,QImage::Format_RGB32);
                              image.fill(QColor("black"));
                          }
                          
                          QImage OpencvImageProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize)
                          {
                              Q_UNUSED(id);
                          
                              if(size){
                                  *size = image.size();
                              }
                          
                              if(requestedSize.width() > 0 && requestedSize.height() > 0) {
                                  image = image.scaled(requestedSize.width(), requestedSize.height(), Qt::KeepAspectRatio);
                              }
                              return image;
                          }
                          
                          void OpencvImageProvider::updateImage(const QImage &image)
                          {
                              if(!image.isNull() && this->image != image) {
                                  this->image = image;
                                  emit imageChanged();
                              }
                          }
                          
                          
                          jsulmJ Offline
                          jsulmJ Offline
                          jsulm
                          Lifetime Qt Champion
                          wrote on last edited by
                          #20

                          @Arev You did not answer my question

                          https://forum.qt.io/topic/113070/qt-code-of-conduct

                          A 2 Replies Last reply
                          0
                          • jsulmJ jsulm

                            @Arev You did not answer my question

                            A Offline
                            A Offline
                            Arev
                            wrote on last edited by
                            #21

                            @jsulm
                            Yes, from Qt creator

                            1 Reply Last reply
                            0
                            • jsulmJ jsulm

                              @Arev You did not answer my question

                              A Offline
                              A Offline
                              Arev
                              wrote on last edited by
                              #22

                              @jsulm

                              In the .pro file I have not added these two lines

                              CONFIG += link_pkgconfig
                              PKGCONFIG += opencv4
                              

                              could this be the reason?
                              And after adding I get this problem:

                              opencv4 development package not found

                              SGaistS 1 Reply Last reply
                              0
                              • A Arev

                                @jsulm

                                In the .pro file I have not added these two lines

                                CONFIG += link_pkgconfig
                                PKGCONFIG += opencv4
                                

                                could this be the reason?
                                And after adding I get this problem:

                                opencv4 development package not found

                                SGaistS Offline
                                SGaistS Offline
                                SGaist
                                Lifetime Qt Champion
                                wrote on last edited by
                                #23

                                @Arev hi,

                                Are you sure about the pkgconfig package name ? If so, where is its .pc file located ?

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

                                A 1 Reply Last reply
                                0
                                • SGaistS SGaist

                                  @Arev hi,

                                  Are you sure about the pkgconfig package name ? If so, where is its .pc file located ?

                                  A Offline
                                  A Offline
                                  Arev
                                  wrote on last edited by
                                  #24

                                  @SGaist said in Errors: undefined reference to cv::VideoCapture::VideoCapture():

                                  .pc

                                  what is .pc file (
                                  I do not have that file, where can I get

                                  SGaistS 1 Reply Last reply
                                  0
                                  • A Arev

                                    @SGaist said in Errors: undefined reference to cv::VideoCapture::VideoCapture():

                                    .pc

                                    what is .pc file (
                                    I do not have that file, where can I get

                                    SGaistS Offline
                                    SGaistS Offline
                                    SGaist
                                    Lifetime Qt Champion
                                    wrote on last edited by
                                    #25

                                    @Arev it's the pkgconfig configuration file. Each library / framework can provide it (or you can create your own).

                                    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
                                    1

                                    • Login

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