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()

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

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
25 Posts 6 Posters 3.3k Views
  • 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.
  • R Ronel_qtmaster
    17 Apr 2024, 12:10

    You need to use opencv compatible with your Qt version and KIt.
    Did you compile opencv yourself?If no use cmake to compile opencv for your Qt version, Then test it with mingw32.

    A Offline
    A Offline
    Arev
    wrote on 17 Apr 2024, 12:15 last edited by
    #3

    @Ronel_qtmaster

    I compile it with mingw32

    1 Reply Last reply
    0
    • R Ronel_qtmaster
      17 Apr 2024, 12:10

      You need to use opencv compatible with your Qt version and KIt.
      Did you compile opencv yourself?If no use cmake to compile opencv for your Qt version, Then test it with mingw32.

      A Offline
      A Offline
      Arev
      wrote on 17 Apr 2024, 12:28 last edited by
      #4

      @Ronel_qtmaster

      and I need to implement it in qmake environment, not cmake

      J 1 Reply Last reply 17 Apr 2024, 13:03
      0
      • A Arev
        17 Apr 2024, 12:28

        @Ronel_qtmaster

        and I need to implement it in qmake environment, not cmake

        J Offline
        J Offline
        JonB
        wrote on 17 Apr 2024, 13:03 last edited by
        #5

        @Arev
        You should tell us exactly which version of opencv you are using with the old Qt and where you got that -lopencv_world490 is the only cv library you need to link with.

        A P 2 Replies Last reply 17 Apr 2024, 13:16
        0
        • J JonB
          17 Apr 2024, 13:03

          @Arev
          You should tell us exactly which version of opencv you are using with the old Qt and where you got that -lopencv_world490 is the only cv library you need to link with.

          A Offline
          A Offline
          Arev
          wrote on 17 Apr 2024, 13:16 last edited by
          #6

          @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

          R 1 Reply Last reply 17 Apr 2024, 16:21
          0
          • J JonB
            17 Apr 2024, 13:03

            @Arev
            You should tell us exactly which version of opencv you are using with the old Qt and where you got that -lopencv_world490 is the only cv library you need to link with.

            P Online
            P Online
            Pl45m4
            wrote on 17 Apr 2024, 13:16 last edited by Pl45m4
            #7

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

            where you got that -lopencv_world490 is the only cv library you need to link with.

            Actually opencv_world is a collection of all OpenCV modules. It's pretty packed and huge, but AFAIK you can do it instead of linking core, imgprocetc separately.


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

            ~E. W. Dijkstra

            J 1 Reply Last reply 17 Apr 2024, 13:24
            0
            • P Pl45m4
              17 Apr 2024, 13:16

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

              where you got that -lopencv_world490 is the only cv library you need to link with.

              Actually opencv_world is a collection of all OpenCV modules. It's pretty packed and huge, but AFAIK you can do it instead of linking core, imgprocetc separately.

              J Offline
              J Offline
              JonB
              wrote on 17 Apr 2024, 13:24 last edited by JonB
              #8

              @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... :)

              P 1 Reply Last reply 17 Apr 2024, 13:36
              0
              • J JonB
                17 Apr 2024, 13:24

                @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... :)

                P Online
                P Online
                Pl45m4
                wrote on 17 Apr 2024, 13:36 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 18 Apr 2024, 06:38
                1
                • A Arev
                  17 Apr 2024, 13:16

                  @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

                  R Offline
                  R Offline
                  Ronel_qtmaster
                  wrote on 17 Apr 2024, 16:21 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
                  • P Pl45m4
                    17 Apr 2024, 13:36

                    @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 18 Apr 2024, 06:38 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;
                    
                    J 2 Replies Last reply 18 Apr 2024, 06:40
                    0
                    • A Arev
                      18 Apr 2024, 06:38

                      @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;
                      
                      J Offline
                      J Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on 18 Apr 2024, 06:40 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 18 Apr 2024, 08:40
                      0
                      • J jsulm
                        18 Apr 2024, 06:40

                        @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 18 Apr 2024, 08:40 last edited by
                        #13

                        @jsulm

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

                        J 1 Reply Last reply 18 Apr 2024, 09:37
                        0
                        • A Arev
                          18 Apr 2024, 06:38

                          @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;
                          
                          J Offline
                          J Offline
                          jsulm
                          Lifetime Qt Champion
                          wrote on 18 Apr 2024, 08:50 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 18 Apr 2024, 09:06
                          0
                          • J jsulm
                            18 Apr 2024, 08:50

                            @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 18 Apr 2024, 09:06 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.

                            J 1 Reply Last reply 18 Apr 2024, 09:15
                            0
                            • A Arev
                              18 Apr 2024, 09:06

                              @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.

                              J Offline
                              J Offline
                              jsulm
                              Lifetime Qt Champion
                              wrote on 18 Apr 2024, 09:15 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 18 Apr 2024, 09:21
                              0
                              • J jsulm
                                18 Apr 2024, 09:15

                                @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 18 Apr 2024, 09:21 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
                                  18 Apr 2024, 08:40

                                  @jsulm

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

                                  J Offline
                                  J Offline
                                  jsulm
                                  Lifetime Qt Champion
                                  wrote on 18 Apr 2024, 09:37 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 18 Apr 2024, 09:57
                                  1
                                  • J jsulm
                                    18 Apr 2024, 09:37

                                    @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 18 Apr 2024, 09:57 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();
                                        }
                                    }
                                    
                                    
                                    J 1 Reply Last reply 18 Apr 2024, 12:23
                                    0
                                    • A Arev
                                      18 Apr 2024, 09:57

                                      @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();
                                          }
                                      }
                                      
                                      
                                      J Offline
                                      J Offline
                                      jsulm
                                      Lifetime Qt Champion
                                      wrote on 18 Apr 2024, 12:23 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 18 Apr 2024, 12:26
                                      0
                                      • J jsulm
                                        18 Apr 2024, 12:23

                                        @Arev You did not answer my question

                                        A Offline
                                        A Offline
                                        Arev
                                        wrote on 18 Apr 2024, 12:26 last edited by
                                        #21

                                        @jsulm
                                        Yes, from Qt creator

                                        1 Reply Last reply
                                        0
                                        • J jsulm
                                          18 Apr 2024, 12:23

                                          @Arev You did not answer my question

                                          A Offline
                                          A Offline
                                          Arev
                                          wrote on 19 Apr 2024, 12:43 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 19 Apr 2024, 21:34
                                          0

                                          12/25

                                          18 Apr 2024, 06:40

                                          • Login

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