以前一直基於Windows平臺(Win 7 32bit)使用VS2010作OpenCV的開發,如今開始學習在Windows 下使用Qt作OpenCV的開發。本文主要講述Windows平臺下(Win 7 32bit)下Qt5.5.0和OpenCV2.4.9環境的搭建。在此以前,我已安裝好Qt5.5.0(with MinGW492)和OpenCV2.4.9(for Windows),而且配置好了它們的環境變量。windows
如今咱們使用CMake生成Qt版本OpenCV的安裝工程,我使用的CMake版本是CMake 3.5.1。ide
(1)啓動CMake,輸入源地址和目標地址(個人目標地址是本身在OpenCV的安裝目錄下新建的名爲build_qt5的文件夾),執行Configure,以下圖所示。函數
(2)肯定沒有錯誤後,執行Generate,完成後會在D:\OpenCV249\build_qt5目錄下生成Qt版OpenCV的安裝工程。工具
(1)Generate完成後,關閉CMake窗口。在D:\OpenCV249\build_qt5目錄下,經過CMD控制檯窗口執行mingw32-make命令,編譯剛纔生成的工程。這會須要一段時間,在我電腦上大約用了20分鐘。學習
(2)上一步執行完後,再在該命令行窗口執行mingw32-make install命令。開發工具
(3)添加環境變量,將bin文件夾所在的路徑(以下)添加到Path變量中。測試
D:\OpenCV249\build_qt5\bin
(1)安裝好OpenCV後,新建Qt工程,我創建的是Qt控制檯工程,測試OpenCV環境搭建是否正確。ui
(2)在工程的pro文件中,添加OpenCV的include路徑和lib路徑,以下所示。spa
INCLUDEPATH += D:\OpenCV249\build\include\ LIBS += D:\OpenCV249\build_qt5\lib\libopencv_calib3d249.dll.a\ D:\OpenCV249\build_qt5\lib\libopencv_contrib249.dll.a\ D:\OpenCV249\build_qt5\lib\libopencv_core249.dll.a\ D:\OpenCV249\build_qt5\lib\libopencv_features2d249.dll.a\ D:\OpenCV249\build_qt5\lib\libopencv_flann249.dll.a\ D:\OpenCV249\build_qt5\lib\libopencv_gpu249.dll.a\ D:\OpenCV249\build_qt5\lib\libopencv_highgui249.dll.a\ D:\OpenCV249\build_qt5\lib\libopencv_imgproc249.dll.a\ D:\OpenCV249\build_qt5\lib\libopencv_legacy249.dll.a\ D:\OpenCV249\build_qt5\lib\libopencv_ml249.dll.a\ D:\OpenCV249\build_qt5\lib\libopencv_objdetect249.dll.a\ D:\OpenCV249\build_qt5\lib\libopencv_video249.dll.a
(3)在main函數中添加以下代碼:.net
//read a image Mat image= cv::imread("C:\\Users\\Gordon\\Desktop\\OpenCVTest\\test.jpg",1); // 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);
(4)構建、運行工程,效果以下圖所示。
[1] Win7下qt5.3.1+opencv2.4.9編譯環境的搭建 http://blog.csdn.net/zhaocj/article/details/38944037