本文共 4967 字，大约阅读时间需要 16 分钟。
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.
3 Compiling OpenCV
OnceCMake installed, you can start the gui-based application (
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.
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/188.8.131.52/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/184.108.40.206/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
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
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.
And don't forgetthat you need to change the DLL names to 244 instead of 231, like this:
LIBS +=-LC:\\software\\opencvMinGW\\install\\lib \