windows上 QtCreator调用OpenCv

辗转反侧学了一段时间Python,然后发现公司需要的是界面,于是又学了一段时间的PyQt,然后发现Qt是用C写的。这样的话于是又去配置Qt了。Qt是C++写的,信号槽什么的还是保留着python的特色,因为项目只需要C++代码,也没有其他太大的问题,就着手写了个界面了。

Qt Creator下载地址 http://www.qt.io/download-open-source/#section-2。或者http://www.qt.io/download/拉到最后下载opensource,进入页面后,有个View All Download。进入后下载。注意是x多少的,如果配置后出现模块计算机类型“x86”与目标计算机类型“x64”冲突的话。就下个32位的Qt吧。

然后写好了,同事需要调Qt调用OpenCv的内容,所以又着手帮他调通。感觉不难但很多坑,琢磨了几天好像。

1、安装OpenCv,就官网上下载个openCv的解压版就好了。注意是x多少的,如果配置后出现模块计算机类型“x86”与目标计算机类型“x64”冲突的话。就下个32位的OpenCv

2、千万不要解压在有空格的文件夹名字目录下。例如D:\Program Files\opencv这样的目录,不然import的时候会哭的。

好了,下面在.pro上添加OpenCv路径

INCLUDEPATH += E:\opencv\build\include\
INCLUDEPATH += E:\opencv\build\include\
INCLUDEPATH += E:\opencv\build\include\


LIBS+=E:\opencv\build\x86\vc12\lib\opencv_ml249d.lib
LIBS+=E:\opencv\build\x86\vc12\lib\opencv_calib3d249d.lib
LIBS+=E:\opencv\build\x86\vc12\lib\opencv_contrib249d.lib
LIBS+=E:\opencv\build\x86\vc12\lib\opencv_core249d.lib
LIBS+=E:\opencv\build\x86\vc12\lib\opencv_features2d249d.lib
LIBS+=E:\opencv\build\x86\vc12\lib\opencv_flann249d.lib
LIBS+=E:\opencv\build\x86\vc12\lib\opencv_gpu249d.lib
LIBS+=E:\opencv\build\x86\vc12\lib\opencv_highgui249d.lib
LIBS+=E:\opencv\build\x86\vc12\lib\opencv_imgproc249d.lib
LIBS+=E:\opencv\build\x86\vc12\lib\opencv_legacy249d.lib
LIBS+=E:\opencv\build\x86\vc12\lib\opencv_objdetect249d.lib
LIBS+=E:\opencv\build\x86\vc12\lib\opencv_ts249d.lib
LIBS+=E:\opencv\build\x86\vc12\lib\opencv_video249d.lib
LIBS+=E:\opencv\build\x86\vc12\lib\opencv_nonfree249d.lib
LIBS+=E:\opencv\build\x86\vc12\lib\opencv_ocl249d.lib
LIBS+=E:\opencv\build\x86\vc12\lib\opencv_photo249d.lib
LIBS+=E:\opencv\build\x86\vc12\lib\opencv_stitching249d.lib
LIBS+=E:\opencv\build\x86\vc12\lib\opencv_superres249d.lib
LIBS+=E:\opencv\build\x86\vc12\lib\opencv_videostab249d.lib


然后在随便个.cpp文件上导入头文件

#include
#include
using namespace cv;

再随便找网上的代码贴一下

    Mat image= imread("./IMG_1184 002.jpg");
       // avoid mem error
       if (image.empty()){
   
           namedWindow("can not find image : img.jpg");
           waitKey(5000);
           return -1;
   }
       //creat image windows named "My Image"
       namedWindow("My Image",1);
       //show the image on window
       imshow("My Image",image);
       //wait key for 5000ms
       waitKey(0);
运行成功的话,大概就调成功了

你可能感兴趣的:(工具使用,qtcreator,opencv)