Clion+Qt+Opencv详细配置
1、下载opencv
这里下载3.4版本的,下载4.0版本容易出错
2、安装opencv
D:\opencv\opencv-3.4.16\opencv
3、CMake构建
3.1 添加源文件和目标文件
3.2 选择mingw构建
3.3 选择c和c++编译工具
D:/Qt/Qt5.14.2/Tools/mingw730_64/bin/gcc.exe
D:/Qt/Qt5.14.2/Tools/mingw730_64/bin/g++.exe
3.4 编译中
3.5 第一次编译完
3.6 添加文件ffpeg
D:\opencv\opencv-3.4.16\opencv\mingw32-build\3rdparty\ffmpeg
复制到:D:\opencv\opencv-3.4.16\opencv\sources.cache\ffmpeg
之后重新configure
3.7 勾选/不勾选
不勾选:
(1)ENABLE_PRECOMPILED_HEADERS
(2)WITH_MSMF
(3)WITH_IPP
(4)WITH_TBB
(5)OPENCV_ENABLE_ALLOCATOR_STATS
勾选:
- with_qt
- with_opengl
- enable_cxx
点击configure
3.8 选择QT文件
QT_QMAKE_EXECUTABLE D:/Qt/Qt5.14.2/5.14.2/mingw73_64/bin/qmake.exe
Qt5Dir D:/Qt/Qt5.14.2/5.14.2/mingw73_64/lib/cmake/Qt5
点击configure
点击configure
3.9 生成
没有红色则生成
4、编译安装
mingw32-make -j8
mingw32-make install
5、配置环境变量
D:\opencv\opencv-3.4.16\opencv\mingw32-build\install\x64\mingw\bin
6、CMakeLists
set(OpenCV_DIR D:/opencv/opencv-3.4.16/opencv/mingw32-build/install)
find_package(OpenCV REQUIRED)
target_link_libraries(qt_demo1 ${OpenCV_LIBS})
7、测试代码
#include "Headers/mainwindow.h"
#include "Forms/ui_MainWindow.h"
#include <opencv2/opencv.hpp>
#include <string>
using namespace std;
using namespace cv;
MainWindow::MainWindow(QWidget *parent) :
QWidget(parent), ui(new Ui::MainWindow) {
ui->setupUi(this);
Mat image = imread("D:\\Desktop\\1.jpg",1);
namedWindow("Display window",WINDOW_AUTOSIZE);
imshow("Display window",image);
}
MainWindow::~MainWindow() {
delete ui;
}
这样写点击运行没有反应,缺少相应的库,讲Qt/mingw下的两个文件移到debug目录(Qt5OpenGL.dll Qt5Test.dll)
再次运行