Qt配置OpenCV

1、安装Qt MSVC版(Qt 5.5.1)

2、安装Debugging Tools for Windows,调试程序时要用到的。

3、打开Qt新建一个控制台程序,新建一个main.cpp,输入以下代码:

#include 
#include 
#include 

using namespace cv;
using namespace std;

int main()
{
    Mat input_image;
    string image_path = "D:\\Projects\\QtProjects\\TestQtOpenCV\\test.jpg";
    input_image = imread(image_path);

    if(input_image.empty())
    {
       cout << "load image failed!" << endl;
       return -1;
    }

    imshow("color-image", input_image);

    Mat gray_image;
    cvtColor(input_image, gray_image, CV_BGR2GRAY);
    imshow("gray-imag", gray_image);

    waitKey(0);
    return 0;
}

4、工程配置文件(.pro文件)内容如下

SOURCES += \
    main.cpp

INCLUDEPATH += C:\opencv\build\include \
               C:\opencv\build\include\opencv \
               C:\opencv\build\include\opencv2

CONFIG(debug, debug|release):
{
LIBS += -LC:\opencv\build\x86\vc11\lib\
-lopencv_calib3d249d \
-lopencv_contrib249d \
-lopencv_core249d \
-lopencv_features2d249d \
-lopencv_flann249d \
-lopencv_gpu249d \
-lopencv_highgui249d \
-lopencv_imgproc249d \
-lopencv_legacy249d \
-lopencv_ml249d \
-lopencv_nonfree249d \
-lopencv_objdetect249d \
-lopencv_ocl249d \
-lopencv_photo249d \
-lopencv_stitching249d \
-lopencv_superres249d \
-lopencv_ts249d \
-lopencv_video249d \
-lopencv_videostab249d
}

5、执行qmake,然后构建工程,就可以运行了。

你可能感兴趣的:(Qt学习)