在下载openCV官网http://opencv.org/ 选择下载 OpenCV for windows(我下载的是2.49)
解压到D盘openCV目录下 D:\openCV
4.4 在cmd终端,进入D:\openCV\opencv\minGW_bulid输入以下俩个命令:
minGW32-make
minGW32-make install
这个过程有点长,我i7处理器编译了10分钟,
#配置openCV的include
INCLUDEPATH += D:\Qt5\openCV\include\opencv2
INCLUDEPATH += D:\Qt5\openCV\include\opencv
INCLUDEPATH += D:\Qt5\openCV\include
#配置OpenCV的lib
LIBS+=D:\Qt5\openCV\lib\libopencv_ml249.dll.a
LIBS+=D:\Qt5\openCV\lib\libopencv_calib3d249.dll.a
LIBS+=D:\Qt5\openCV\lib\libopencv_contrib249.dll.a
LIBS+=D:\Qt5\openCV\lib\libopencv_core249.dll.a
LIBS+=D:\Qt5\openCV\lib\libopencv_features2d249.dll.a
LIBS+=D:\Qt5\openCV\lib\libopencv_flann249.dll.a
LIBS+=D:\Qt5\openCV\lib\libopencv_gpu249.dll.a
LIBS+=D:\Qt5\openCV\lib\libopencv_highgui249.dll.a
LIBS+=D:\Qt5\openCV\lib\libopencv_imgproc249.dll.a
LIBS+=D:\Qt5\openCV\lib\libopencv_legacy249.dll.a
LIBS+=D:\Qt5\openCV\lib\libopencv_objdetect249.dll.a
LIBS+=D:\Qt5\openCV\lib\libopencv_ts249.a
LIBS+=D:\Qt5\openCV\lib\libopencv_video249.dll.a
LIBS+=D:\Qt5\openCV\lib\libopencv_nonfree249.dll.a
LIBS+=D:\Qt5\openCV\lib\libopencv_ocl249.dll.a
LIBS+=D:\Qt5\openCV\lib\libopencv_photo249.dll.a
LIBS+=D:\Qt5\openCV\lib\libopencv_stitching249.dll.a
LIBS+=D:\Qt5\openCV\lib\libopencv_superres249.dll.a
LIBS+=D:\Qt5\openCV\lib\libopencv_videostab249.dll.a
在main函数中使用如下程序:
注意:(1)需要在程序中放置一个图片,图片使用绝对路径,相对路径不好使
#include <QCoreApplication>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main(int argc,char **argv)
{
cout<<"opencv"<<endl;
Mat src=imread("E:\\CODE\\QT\\OpenCVTest\\test.jpg"); //在qt里面读取图片貌似只支持绝对路径
imshow("test",src);
waitKey(0);
return 0;
}