網頁

2014年5月23日 星期五

Build OpenCV

  1. Microsoft Visual Studio
  2. Download CMake: www.cmake.org
    ... and install it.
    選 Do not add Cmake to system PATH
  3. Download msysgit and install it.
    msysgit 已經改成 git for windows
    Download TortoiseGit: http://code.google.com/p/tortoisegit/
    ... and install it.
    Note: After this you may need to restart your system.
  4. 建立目錄 C:/OpenCV
    Clone the repository to C:\OpenCV from https://github.com/Itseez/opencv.git
    1. Download Python: https://www.python.org/downloads/ and install it.
      若是使用 Python34 版本,會在建立文件時出錯,為了確認這一點,花了不少時間。
      下載x86(32位元)和amd64(64位元)版本,分別安裝於不同目錄。
      安裝 Setuptools
      下載 ez_setup.py 置於 C:\Python27_32 下
      執行 C:\Python27_32>python ez_setup.py
    2. Start up a command window and navigate to your Python install Scripts folder.
      Install Sphinx via the command:
      C:\Python27_32\Scripts\easy_inatall.exe sphinx
    3. Download and install Numpy: http://sourceforge.net/projects/numpy/files/NumPy/1.8.1/
      注意相對 Python 的版本
    4. Download and install Miktex: http://miktex.org/.
      At the fourth step make sure you select for the "Install missing packages" the Yes option.
    5. Download the Intel TBB library: https://www.threadingbuildingblocks.org/, 選擇 Windows 版本
      Extract it.
      Create a dep directory in your OpenCV folder.
      And copy the extracted files here.
    6. Do the same with the eigen files: eigen.tuxfamily.org
    7. And again with the OpenEXR source files: http://www.openexr.com/
      這個好像不用裝。
    8. For OpenNI first download and install the binaries:
      http://www.openni.org/downloadfiles/opennimodules
      Then the PrimeSensor moudle (OpenNI Compliant Hardware Binaries).
      我沒有這個東西。
    9. To use CUDA you need to install the latest CUDA Toolkit...
      and the Cuda Tools SDK.
      CUDA 並不支援 VS2013
    10. Qt - You first need to download the source files: http://qt-project.org/
      Then extract them to a final path (should be a short one).
      When finished start up a Visual Studio Command Prompt (2010) from the start menu.
      Navigate to your Qt folder.
      Now enter the command: configure.exe -release -no-webkit -no-phonon -no-phorion -backend -no-script -no-scripttools -no-qt3support -no-multimedia -no-itcg
      Answer to the license agreement.
      Then wait as it could easily take up to a half hour to finish.
      Once finished just enter the nmake command.
      Building the library will take a lot longer then the previous step...
      QT5 64bit 參考如下:
      add C:\Python27_64 to PATH
      開啟 C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\Shortcuts\VS2013 x64 Native Tools Command Prompt
      set QMAKESPEC=C:\OpenCV\dep\qt5_64\qtbase\mkspecs\win32-msvc2013
      configure.bat -debug-and-release -platform win32-msvc2013 -nomake examples
      nmake
      若是失敗要重來,就整個目錄刪除比較快。
      add C:\OpenCV\dep\qt5_64 to QTDIR
      add C:\OpenCV\dep\qt5_64\qtbase\bin to PATH
      QT5 32bit 參考如下:
      add C:\Python27_32 to PATH
      開啟 C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\Shortcuts\VS2013 x86 Native Tools Command Prompt
      set QMAKESPEC=C:\OpenCV\dep\qt5_32\qtbase\mkspecs\win32-msvc2013
      configure.bat -debug-and-release -platform win32-msvc2013 -nomake examples
      nmake
      若是失敗要重來,就整個目錄刪除比較快。
      add C:\OpenCV\dep\qt5_32 to QTDIR
      add C:\OpenCV\dep\qt5_32\qtbase\bin to PATH
  5. Now we can build the OpenCV library.
    First start the CMake Gui from the start menu.
    Then select where your source files are and where your want your build files to be.
    Choose the compiler (IDE) you use.
    Note: They are different compiler for 32 and 64 bit.
    CMake will try to search for as many libraries as possible.
    For the ones he cannot find a NOTFOUND constant is set.
    You need to specify these manually.
    Under the WITH group you can select which 3th party libraries to use for the build.
    Under the BUILD group you can specify which extra OpenCV parts to build.
    Set all not found constant to the correct path.
    In ENABLE group enable the solution folders in order to make an organized Visual Studio solution.
    Look arund the items and set any further not found constants.
    Then press the configure button to test them.
    This will bring up some new not found constants. specify them manually.
    Then press again the configure for validation.
    Repeat this procedure until all the entries are accepted.
    Then press the Generate to make the solution and project files.
    Now in the build directory you have the OpenCV solution. Open it.
    Then Build the ALL_BUILD project.
    Do it for both the Debug and Release configuration.
    Depanding on just how much of OpenCV you are building this can take quite long...
    If you haven't yet you might need to add the Intel TBB bin folders content to the system path. Again use the Path Editor.
    To test if your build works start up the generated exe files from your build directory.
    For example contours.exe...
    To collect the built binary files into a single folder built the install project.
    In the install folder you will have all the files of OpenCV that you will use inside your projects.
    That's it. You are done!
    以下步驟紀錄:
    Visual Studio 12 ==> VS2013 x86
    Visual Studio 12 Win64 ==> VS2013 x64
    勾選 Grouped 和 Advanced
    SPHINX_BUILD=C:/Python27/Scripts/sphinx-build.exe
    EIGEN_INCLUDE_PATH=C:/OpenCV/dep/eigen
    選 WITH_QT
    QT_QMAKE_EXECUTABLE=C:/OpenCV/dep/qt5_64/qtbase/qmake/qmake.exe
    Qt5OpenGL_DIR=C:/OpenCV/dep/qt5_64/qtbase/lib/cmake/Qt5OpenGL
    Qt5Concurrent_DIR=C:/OpenCV/dep/qt5_64/qtbase/lib/cmake/Qt5Concurrent
    Qt5Core_DIR=C:/OpenCV/dep/qt5_64/qtbase/lib/cmake/Qt5Core
    Qt5Gui_DIR=C:/OpenCV/dep/qt5_64/qtbase/lib/cmake/Qt5Gui
    Qt5Test_DIR=C:/OpenCV/dep/qt5_64/qtbase/lib/cmake/Qt5Gui
    Qt5Widgets_DIR=C:/OpenCV/dep/qt5_64/qtbase/lib/cmake/Qt5Widgets
    選 WITH_TBB, 不選 BUILD_TBB
    TBB_INCLUDE_DIRS=C:/OpenCV/dep/tbb42_20140122oss/include
    TBB_LIB_DIR=C:/OpenCV/dep/tbb42_20140122oss/lib/ia32/vc12
    TBB_STDDEF_PATH=C:/OpenCV/dep/tbb42_20140122oss/include/tbb/tbb_stddef.h
    選 WITH_IPP, WITH_IPP_A
    IPP_A_INCLUDE_DIR=C:/Program Files (x86)/Intel/IPP Preview 2014 February/ipp/include
    IPP_A_LIBRARIES=C:/Program Files (x86)/Intel/IPP Preview 2014 February/ipp/lib/intel64/ipp_async_preview.lib
    PYTHON_INCLUDE_DIR=C:/Python27/include
    PYTHON_LIBRARY=C:/Python27/libs/python27.lib
    PYTHON_LIBRARY_RELEASE=C:/Python27/libs/python27.lib
  6. 用 VisualStudio2013 開啟 C:\OpenCV\Builds\OpenCV.sln
    Build Debug 會有一個失敗,因為缺少 python27_d.lib
    Build Release
    Build documentation/docs or documentation/html_docs 單獨的
    Build CMakeTargets/INSTALL 單獨的

沒有留言:

張貼留言