如何在QT环境中使用openCV

1 Download

  QT:http://qt-project.org/downloads

  openCV:http://opencv.willowgarage.com/wiki/

  CMkae:cmake.org

 

2 Installations

  Install Qt (This will take quite a while).

  Run the openCV exe which will extract all thefiles you need. As stated   earlier, Iused C:\software\opencv-win as the location to where to extract   them.

 

  Install CMake. Make sure to select "AddCMake to system path for all  users" (or similar).

  Add C:\software\qt\5.0.1\mingw47_32\bin  and c:\software\5.0.1\tools\mingw48_32\bin (orequivalent) to path in System   variables(How to do this is described in the guide I linked in the   beginning.

  RESTART COMPUTER.

 

3 Compiling OpenCV

OnceCMake installed, you can start the gui-based application (cmake-gui)

  Under "Where is the source code:"You browse to where you   unzipped opencv(in my case C:\software\opencv-win(也就是提取opencv的路径,这里要特别说明一下,所选的路径必须是包含CMakeLists.txt这个文件的)), and in "Where to  build the binaries", you enter where you want the finishedlibraries (I   usedc:\software\opencvMinGW), then click generate and create directory.   At the popup window, you choose "MinGWmakefiles" and "Specify native  compilers". At C, for me the path became   "C:/software/qt/Tools/MinGW/bin/gcc.exe",and for C++  "C:/software/qt/Tools/MinGW/bin/g++.exe", you enter accordinglywhere you   installed Qt.

Press configure.

 

This is wherethings got funky for me. I got an error saying:

 

"CMakeError: CMake was unable to find a build program corresponding to "MinGWMakefiles". CMAKE_MAKE_PROGRAM is not set. You probably need to select adifferent build tool. CMake Error: CMake was unable to find a build programcorresponding to "MinGW Makefiles". CMAKE_MAKE_PROGRAM is not set.You probably need to select a different build tool. CMake Error: Error requiredinternal CMake variable not set, cmake may be not be built correctly. Missingvariable is: CMAKE_CXX_COMPILER_ENV_VAR CMake Error: Could not find cmakemodule file:C:/software/opencvMinGWblah/CMakeFiles/2.8.10.2/CMakeCXXCompiler.cmakeCMake Error: Error required internal CMake variable not set, cmake may be notbe built correctly. Missing variable is: CMAKE_C_COMPILER_ENV_VAR CMake Error:Could not find cmake module file:C:/software/opencvMinGWblah/CMakeFiles/2.8.10.2/CMakeCCompiler.cmakeConfiguring incomplete, errors occurred!"

 

I suspected thishad to do with the make-program. Duh. But how to fix it?

 

I resolved it bychecking the "Advanced" button, finding the entry CMAKE_MAKE_PROGRAMand specifying the path"C:/software/qt/Tools/MinGW/bin/mingw32-make.exe"

 

All is well thatends well. Or is it?

Check the"Grouped" button, open the WITH category, check "WITH_QT".Press configure. Another chunk of errors:

CMake Warning atC:/software/CMake 2.8/share/cmake-2.8/Modules/FindQt4.cmake:615 (message):C:/software/qt/5.0.1/mingw47_32/bin/qmake.exe reported QT_INSTALL_LIBS as"C:/software/qt/5.0.1/mingw47_32/lib" but QtCore could not be foundthere. Qt is NOT installed correctly for the target build environment. CallStack (most recent call first):

cmake/OpenCVFindLibsGUI.cmake:8(find_package) CMakeLists.txt:377 (include)

 

So, as one mightsuspect from the error message, the program can't find the libraries. Iremedied this as follows. Expand the categori QT, find the valueQT_QTCORE_LIBRARY_DEBUG, enter

 

"C:/software/qt/5.0.1/mingw47_32/bin/Qt5Cored.dll"and just below it you'll find QT_QTCORE_LIBRARY_RELEASE, enter"C:/software/qt/5.0.1/mingw47_32/bin/Qt5Core.dll" NOW, you can pressconfigure (hopefully) witho0ut warnings and after that you can press Generateand everything will be dandy and you can follow the cookbook tutorial.

 

Now that you have completed theinstallation, you are ready to compile the OpenCV library. Start the Windowscmd console and go to the directory where you installed your builds. Typemingw32-make

NOTICE( the OpenCV-2.3.1 is the  directory Where  to  build the binaries in the CMAKE GUI,也就是相当于c:\software\opencvMinGW)

Building everything will take time…..

Once this built completed, you type mingw32-make install

This last step will install the library and the include files inthe install directory. Note that for clarity, you can rename this directoryas release since you ask CMake to build a Release install.

Before we build our first OpenCV project, we need to add a fewmore folders to the Path environment variable. First,you need to tell your system where to find the OpenCV dlls. From ourinstallation process, they are in C:\OpenCV-2.3.1\install\bin.

 

 

Btw, these arethe additional path variables I added to System Variables. I dunno, maybe acouple of them are unneccesary but I'm not about to start messing with themwhen everything finally works.

 

C:\software\qt\Tools\MinGW\bin;

C:\software\Qt\Tools\MinGW;

C:\software\opencvMinGW\install\bin;

And don't forgetthat you need to change the DLL names to 244 instead of 231, like this:

 

LIBS +=-LC:\\software\\opencvMinGW\\install\\lib \

    -lopencv_core244.dll \

    -lopencv_highgui244.dll \

    -lopencv_imgproc244.dll \

    -lopencv_features2d244.dll \

-lopencv_calib3d244.dll

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

视图猿人

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值