一、安转步骤
- download QT5.9
- download Cmake
- download openCV3.2 sources code
- make & make insatll opencv with using Cmake
- 配置环境变量
- run a demo
二、软件下载
- QT5.9下载地址:http://download.qt.io/official_releases/qt/
- Cmake 3.9 下载地址:https://cmake.org/download/
- openCV 3.2源码下载地址:https://codeload.github.com/opencv/opencv/zip/3.2.0
三、用Cmake编译openCV3.2
打开Cmake gui,选择openCV3.2源码地址和build目标文件
如果结果报错且出现下载opencv_ffmpeg失败的话用以下方法处理:
手动下载oepncv_ffmpeg,链接:https://pan.baidu.com/s/1kUDgB5P密码:mnua
下载完成之后,ffmpeg_version.cmake、opencv_ffmpeg.dll、opencv_ffmpeg_64.dll 三项复制到opencv源码目录下的3rdparty\ffmpeg目录下面替换,打开文件 ffmpeg.cmake ,将其内容修改为:
message(STATUS"FFMPEG: Package successfully downloaded") include(${CMAKE_CURRENT_LIST_DIR}/ffmpeg_version.cmake)
- 1
- 2
- 3
- 4
打钩WITH_QT和WITH_OPENGL
当Configure完成之后,还是会有报错,我们需要如下修改
在前面红色高亮地方一次修改Value的值,然后再次点击configureE:\Qt\Qt5.9.0\5.9\mingw53_32\lib\cmake\Qt5Concurrent E:\Qt\Qt5.9.0\5.9\mingw53_32\lib\cmake\Qt5Core E:\Qt\Qt5.9.0\5.9\mingw53_32\lib\cmake\Qt5Gui E:\Qt\Qt5.9.0\5.9\mingw53_32\lib\cmake\Qt5OpenGL E:\Qt\Qt5.9.0\5.9\mingw53_32\lib\cmake\Qt5Test E:\Qt\Qt5.9.0\5.9\mingw53_32\lib\cmake\Qt5Widgets
- 4
- 5
- 6
- 7
等待上面操作完成之后,关闭CMake。
到 opencv源码下找到 OpenCVCompilerOptions.cmake,打开文件OpenCVCompilerOptions.cmake,找到add_extra_compiler_option(-Werror=non-virtual-dtor),将其注释掉变为#add_extra_compiler_option(-Werror=non-virtual-dtor)
make & make install
- 在前面build指定的文件夹下打开命令中断,输入:mingw32-make -j4
- 编译好之后,输入: mingw32-make install
配置环境变量
- 在PATH中加入:F:\openCV3_2\install\x86\mingw\bin;F:\openCV3_2\bin
- 重启电脑
四、demo
代开QT Creator,新建一个控制台工程,
打开QtCreator
选择 Qt Console Application
编译器选择 QT5.9.0 MinGW
pro 配置加入下面代码
INCLUDEPATH+=F:\openCV3_2\install\include\ #添加函数头文件目录,根据自己install文件夹目录进行路径修改,下面也一样 F:\openCV3_2\install\include\opencv\ F:\openCV3_2\install\include\opencv2\
- 4
#include<iostream>
#include<opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main(int argc,char *argv[])
{
cv::Mat img;
//cv::VideoCapture cap(0);
while(1)
{
img =imread("C:\\Users\\用户\\Pictures\\ee.png"); //根据自己的目录进行修改,记得用转义字符'//'
//cap>>img;
cv::imshow("a",img);
cv::waitKey(10);
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17