使用Qt创建一个OpenCV工程

要使用Qt创建一个工程

需要以下几步:

第一步:下载安装并配置OpenCV版本;

我用的是OpenCV2.43版本,好像2.2以后的版本可以不用自己编译,使用安装解压出来的库就可以了.

第二步:下载安装并配置Qt

我用的是5.02版本,安装配置好就行了,新版本的一般也不需要配置什么的.

第三步:开始创建一个简单的控制台程序

(1)打开Qt Creator,选择创建一个控制台程序

点击选择:

使用Qt创建一个OpenCV工程_第1张图片

下一步:


点击下一步

使用Qt创建一个OpenCV工程_第2张图片

点击完成创建成功:

(2)创建成功后会有两个文件,一个是main.cpp文件 另一个是XXX.pro文件

点击打开.pro文件

在最后添加:

INCLUDEPATH += E:\opencv\build\include
CONFIG(release,debug|release){
    LIBS += E:\opencv\build\x86\vc10\lib\opencv_calib3d243.lib \
            E:\opencv\build\x86\vc10\lib\opencv_contrib243.lib \
            E:\opencv\build\x86\vc10\lib\opencv_core243.lib \
            E:\opencv\build\x86\vc10\lib\opencv_features2d243.lib \
            E:\opencv\build\x86\vc10\lib\opencv_flann243.lib \
            E:\opencv\build\x86\vc10\lib\opencv_gpu243.lib \
            E:\opencv\build\x86\vc10\lib\opencv_haartraining_engine.lib \
            E:\opencv\build\x86\vc10\lib\opencv_highgui243.lib \
            E:\opencv\build\x86\vc10\lib\opencv_imgproc243.lib \
            E:\opencv\build\x86\vc10\lib\opencv_legacy243.lib \
            E:\opencv\build\x86\vc10\lib\opencv_ml243.lib \
            E:\opencv\build\x86\vc10\lib\opencv_nonfree243.lib \
            E:\opencv\build\x86\vc10\lib\opencv_objdetect243.lib \
            E:\opencv\build\x86\vc10\lib\opencv_photo243.lib \
            E:\opencv\build\x86\vc10\lib\opencv_stitching243.lib \
            E:\opencv\build\x86\vc10\lib\opencv_video243.lib \
            E:\opencv\build\x86\vc10\lib\opencv_videostab243.lib \
}
CONFIG(debug,debug|release){
    LIBS += E:\opencv\build\x86\vc10\lib\opencv_calib3d243d.lib \
            E:\opencv\build\x86\vc10\lib\opencv_contrib243d.lib \
            E:\opencv\build\x86\vc10\lib\opencv_core243d.lib \
            E:\opencv\build\x86\vc10\lib\opencv_features2d243d.lib \
            E:\opencv\build\x86\vc10\lib\opencv_flann243d.lib \
            E:\opencv\build\x86\vc10\lib\opencv_gpu243d.lib \
            E:\opencv\build\x86\vc10\lib\opencv_haartraining_engined.lib \
            E:\opencv\build\x86\vc10\lib\opencv_highgui243d.lib \
            E:\opencv\build\x86\vc10\lib\opencv_imgproc243d.lib \
            E:\opencv\build\x86\vc10\lib\opencv_legacy243d.lib \
            E:\opencv\build\x86\vc10\lib\opencv_ml243d.lib \
            E:\opencv\build\x86\vc10\lib\opencv_nonfree243d.lib \
            E:\opencv\build\x86\vc10\lib\opencv_objdetect243d.lib \
            E:\opencv\build\x86\vc10\lib\opencv_photo243d.lib \
            E:\opencv\build\x86\vc10\lib\opencv_stitching243d.lib \
            E:\opencv\build\x86\vc10\lib\opencv_ts243d.lib \
            E:\opencv\build\x86\vc10\lib\opencv_video243d.lib \
            E:\opencv\build\x86\vc10\lib\opencv_videostab243d.lib \
}
比较懒 把所有库都加上了,以后使用方便;

此处参考了 http://blog.csdn.net/sky_freebird/article/details/6684857 的博客

注意可能includepath包含的路径不一样,需要依据自己机器的情况修改

由于可能使用的openCV文件的版本不一样,可能包含的库不一样,需要自己打开路径查看,库名称后面有个d的是DeBug 版本的;

设置包含路径的时候要注意不要设置错了include路径

我的openCV中的路径中有两个include

E:\opencv\include 

E:\opencv\build\include

设置上面那个是没有用的,需要设置下面的这个路径

使用Qt创建一个OpenCV工程_第3张图片

(3)修改main.cpp文件就可以了

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>

int main()
{
    //read an image
    cv::Mat image = cv::imread("C:\\Users\\chenchao\\Desktop\\airplane.jpg");
    //create image window
    cv::namedWindow("My Image");
    //show the image
    cv::imshow("My Image",image);
    //wait
    cv::waitKey();
    return 1;
}

(4)运行显示成功



程序可在以下联接中下载

http://download.csdn.net/detail/cc7829290/5466711

你可能感兴趣的:(qt,opencv,图像处理)