1.安装QT5.6,在安装时记得勾选上mingw。
2.安装CMake3.11.1
CMake下载地址:https://cmake.org/download/
注意如果有vs存在的话一定要执行这一步,不然找不到编译器:
改变.cmake文件
将 xxxxxxxx\opencv\sources\cmake文件下的OpenCVCompilerOptions.cmake打开,
找到
add_extra_compiler_option(-Werror=non-virtual-dtor)
将其变为
# add_extra_compiler_option(-Werror=non-virtual-dtor)
选择源文件和目标目录
点击configure,选择
选择编译器:
在配置过程中可能存在一直卡在:FFMPEG: Download: opencv_ffmpeg.dll这,先点击stop,在点击配置就好了
不行的话多等待一会。
等待配置完成后,勾选opengl和QT
然后点击configure,这时会报错,我们修改qmake的路径和lib库,如图所示:
再次点击configure,报错,修改opengl路径,:
最后一步,直接点击:Generate:出现Generating done,表示完成Makefile的创建
接下来,cmd切换到目标目录,比如我这是:C:\Users\11011430\Desktop\opencv\BD
输入命令:mingw32-make进行编译。
编译过程中出现的问题:
1.tubs\io_win32.cc:94:3: warning: identifier 'nullptr' is a keyword in C++11
解决方法:勾选上C++11支持,重新Generating
2.
28%左右遇到这种错误:
... windres.exe: unknown option -- W ...
解决方案:
在cmake中 取消勾选 ENABLE_PRECOMPILED_HEADERS
在mingw32-make完成之后,使用mingw32-make install进行安装
新建文件夹qt-opencv,将C:\Users\11011430\Desktop\opencv\build 下面的include文件夹和安装目标文件下面的lib,bin文件夹拷贝到qt-opencv
然后新建QT空项目,添加main.cpp,修改.pro文件:
SOURCES += \
main.cpp
INCLUDEPATH+=C:\Users\11011430\Desktop\opencv-qt\include\opencv\
C:\Users\11011430\Desktop\opencv-qt\include\opencv2\
C:\Users\11011430\Desktop\opencv-qt\include
LIBS+=C:\Users\11011430\Desktop\opencv-qt\lib\libopencv_calib3d_pch_dephelp.a\
C:\Users\11011430\Desktop\opencv-qt\lib\libopencv_calib3d341.dll.a\
C:\Users\11011430\Desktop\opencv-qt\lib\libopencv_core_pch_dephelp.a\
C:\Users\11011430\Desktop\opencv-qt\lib\libopencv_core341.dll.a\
C:\Users\11011430\Desktop\opencv-qt\lib\libopencv_dnn_pch_dephelp.a\
C:\Users\11011430\Desktop\opencv-qt\lib\libopencv_dnn341.dll.a\
C:\Users\11011430\Desktop\opencv-qt\lib\libopencv_features2d_pch_dephelp.a\
C:\Users\11011430\Desktop\opencv-qt\lib\libopencv_features2d341.dll.a\
C:\Users\11011430\Desktop\opencv-qt\lib\libopencv_flann_pch_dephelp.a\
C:\Users\11011430\Desktop\opencv-qt\lib\libopencv_flann341.dll.a\
C:\Users\11011430\Desktop\opencv-qt\lib\libopencv_highgui_pch_dephelp.a\
C:\Users\11011430\Desktop\opencv-qt\lib\libopencv_highgui341.dll.a \
C:\Users\11011430\Desktop\opencv-qt\lib\libopencv_imgcodecs_pch_dephelp.a \
C:\Users\11011430\Desktop\opencv-qt\lib\libopencv_imgcodecs341.dll.a \
C:\Users\11011430\Desktop\opencv-qt\lib\libopencv_imgproc_pch_dephelp.a \
C:\Users\11011430\Desktop\opencv-qt\lib\libopencv_imgproc341.dll.a \
C:\Users\11011430\Desktop\opencv-qt\lib\libopencv_ml_pch_dephelp.a
main.cpp文件为:
#include"cv.h"
#include"cxcore.h"
#include"highgui.h"
int main(int argc,char* argv[])
{
//声明IplImage指针
IplImage*pImg;
//载入图片
pImg=cvLoadImage("F:1.jpg",1);
//创建窗口
cvNamedWindow("Image",1);
//显示图像
cvShowImage("Image",pImg);
//等待按键
cvWaitKey(0);
//销毁窗口
cvDestroyWindow("Image");
//释放图像
cvReleaseImage(&pImg);
return 0;
}
运行,测试成功,在测试中只是加入了部分库文件,在实际开发中自行添加。附上添加全部库的小工具:
https://download.csdn.net/download/qq_31208451/10398028
测试图,哈哈。。。。