I have been struggling for a week to install OpenCV in a Qt environment without success. Please let me know if you discover any potential solutions.
Environment
- Windows11 64bit
- Qt 6.7.3
- Qt Creator 15.0.0
- Cmake 3.26.4
- OpenCV 4.10.0 (any version is fine if it works)
What I have done
- Download OpenCV source files from here (opencv-4.10.0-windows.exe)
- Extract it to
C:/Opencv/opencv/opencv_4_10_0
- Configure with the command below:
cmake -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=C:/mingw64/bin/gcc.exe -DCMAKE_CXX_COMPILER=C:/mingw64/bin/g++.exe C:/Opencv/opencv/opencv_4_10_0/sources
- Build at
C:/Opencv/opencv
cmake --build build_opencv2 --target install
- Add lines below to CMakeList.txt in a project
set(OpenCV_DIR "C:/OpenCV/opencv/build_opencv2/install/x64/mingw/lib")
find_package(OpenCV REQUIRED)
include_directories( ${OpenCV_INCLUDE_DIRS} )
target_link_libraries(VideoPlayer PRIVATE ${OpenCV_LIBS})
- Run the project in Qt Creator
- I got errors like this:
The procedure entry point _ZNSi5seekgESt4fposl9_MbstateE could not be found in the dynamic link library C:\OpenCV\opencv\build_opencv2\install\x64\mingw\bin\libopencv_videoio4100.dll
The issue appears when I include the following line in the header file:
cv::VideoCapture cap;
My script (most part is default setting of Qt creator):
< mainwindow.h>
#include <opencv2/opencv.hpp>
QT_BEGIN_NAMESPACE
namespace Ui {
class MainWindow;
}
QT_END_NAMESPACEclass MainWindow : public QMainWindow
{
Q_OBJECTpublic:
MainWindow(QWidget *parent = nullptr);
~MainWindow();private:
Ui::MainWindow *ui;
cv::VideoCapture cap; # HERE!!!
};
#endif // MAINWINDOW_H
<mainwindow.cpp>
#include “mainwindow.h”
#include “./ui_mainwindow.h”MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
}MainWindow::~MainWindow()
{
delete ui;
}
< main.cpp>
#include “mainwindow.h”
#include
int main(int argc, char *argv)
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}