Errors: undefined reference to cv::VideoCapture::VideoCapture()
-
Re: Ip camera live streaming in QML
Hello everyone, I tried to get the ip camera stream this way, but I'm getting similar problems, which I can't seem to fix.
This is my .pro file
My Qt version is 5.9.9Any help would be greatly appreciated
-
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. -
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.I compile it with mingw32
-
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.and I need to implement it in qmake environment, not cmake
-
and I need to implement it in qmake environment, not cmake
-
@Arev
You should tell us exactly which version ofopencv
you are using with the old Qt and where you got that-lopencv_world490
is the only cv library you need to link with. -
@Arev
You should tell us exactly which version ofopencv
you are using with the old Qt and where you got that-lopencv_world490
is the only cv library you need to link with.@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 linkingcore
,imgproc
etc separately. -
@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 linkingcore
,imgproc
etc separately. -
@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... :)
@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) -
@JonB
I modified it and downloaded the opencv build for mingw from this repositoryhttps://github.com/huihut/OpenCV-MinGW-Build/tree/OpenCV-4.5.5-x64
and I added all libs
@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
-
@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) -
@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 linestatic cv::VideoCapture cap;
@Arev said in Errors: undefined reference to cv::VideoCapture::VideoCapture():
But now my program doesn't open
Then use debugger...
-
@Arev said in Errors: undefined reference to cv::VideoCapture::VideoCapture():
But now my program doesn't open
Then use debugger...
-
@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 linestatic cv::VideoCapture cap;
@Arev said in Errors: undefined reference to cv::VideoCapture::VideoCapture():
static cv::VideoCapture cap
Does it work without this line?
Why is cap static? -
@Arev said in Errors: undefined reference to cv::VideoCapture::VideoCapture():
static cv::VideoCapture cap
Does it work without this line?
Why is cap static?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. -
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. -
I try it and I get the error:
Executable failed: During startup program exited with code 0xc0000135.@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? -
@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?I can share code
This is my .proQT += 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(); } }
-
I can share code
This is my .proQT += 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(); } }