網頁

2014年9月2日 星期二

Build OpenCV v2

使用 Python 2.7, 不要用 Python 3.4, 雖然只是無法Build OpenCV documents
Python有32和64位元, 要分別安裝
Python的debug版本, 要下載 Python 的 source, 用 VS2013 開啟 PCbuild/pcbuild.sln
可以建立出32位元 PCbuild/python27_d.dll並且拷貝至 Python27/libs 下
64位元會置於 PCbuild/amd64/python27_d.dll 下

因為 Intel IPP 會 Build 進 OpenCV 的 library
所以在安裝 Intel IPP 之前,可先建立一版沒有 Intel Ipp 的 OpenCV Library

  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.2/
      注意相對 Python 的版本, 只能下載到32位元, 所以一定會找 Python 32位元版
    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. 從 https://developer.nvida.com/cuda-downloads 下載 CUDA Toolkit
      它有分成Notebook, Desktop, 32/64 等四個版本,請選一個
    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 (2013) 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 單獨的
  7. 設定下列環境變數以便 VisualStudio2013專案 使用
    TBB_DIR_32=C:\OpenCv\dep\tbb43_20140724oss\bin\ia32\vc12
    TBB_DIR_32_ui=C:\OpenCv\dep\tbb43_20140724oss\bin\ia32\vc12_ui
    TBB_DIR_64=C:\OpenCv\dep\tbb43_20140724oss\bin\intel64\vc12
    TBB_DIR_64_ui=C:\OpenCv\dep\tbb43_20140724oss\bin\intel64\vc12_ui
    OPENCV_BIN_32=C:\OpenCv\build_32\install\x86\vc12\bin
    OPENCV_BIN_32_IPP=C:\OpenCv\build_32_ipp\install\x86\vc12\bin
    OPENCV_BIN_64=C:\OpenCv\build_64\install\x64\vc12\bin
    OPENCV_BIN_64_IPP=C:\OpenCv\build_64_ipp\install\x64\vc12\bin
    OPENCV_INC_32=C:\OpenCv\build_32\install\include
    OPENCV_INC_32_IPP=C:\OpenCv\build_32_ipp\install\include
    OPENCV_INC_64=C:\OpenCv\build_64\install\include
    OPENCV_INC_64_IPP=C:\OpenCv\build_64_ipp\install\include
    OPENCV_LIB_32=C:\OpenCv\build_32\install\x86\vc12\lib
    OPENCV_LIB_32_IPP=C:\OpenCv\build_32_ipp\install\x86\vc12\lib
    OPENCV_LIB_64=C:\OpenCv\build_64\install\x64\vc12\lib
    OPENCV_LIB_64_IPP=C:\OpenCv\build_64_ipp\install\x64\vc12\lib
    刪除Path內的C:\OpenCV\dep\qt5_64\qtbase\bin, 另外新增下列兩環境變數
    QT5_32=C:\OpenCV\dep\qt5_32\qtbase\bin
    QT5_64=C:\OpenCV\dep\qt5_64\qtbase\bin
    32/64位元,且有無IPP一樣 Debug Additional Dependencies
    opencv_calib3d300d.lib
    opencv_core300d.lib
    opencv_features2d300d.lib
    opencv_flann300d.lib
    opencv_highgui300d.lib
    opencv_imgcodecs300d.lib
    opencv_imgproc300d.lib
    opencv_ml300d.lib
    opencv_objdetect300d.lib
    opencv_photo300d.lib
    opencv_shape300d.lib
    opencv_stitching300d.lib
    opencv_superres300d.lib
    opencv_ts300d.lib
    opencv_video300d.lib
    opencv_videoio300d.lib
    opencv_videostab300d.lib
    32/64位元,且有無IPP一樣 Release Additional Dependencies
    opencv_calib3d300.lib
    opencv_core300.lib
    opencv_features2d300.lib
    opencv_flann300.lib
    opencv_highgui300.lib
    opencv_imgcodecs300.lib
    opencv_imgproc300.lib
    opencv_ml300.lib
    opencv_objdetect300.lib
    opencv_photo300.lib
    opencv_shape300.lib
    opencv_stitching300.lib
    opencv_superres300.lib
    opencv_ts300.lib
    opencv_video300.lib
    opencv_videoio300.lib
    opencv_videostab300.lib

沒有留言:

張貼留言