1. 程式人生 > >cmake編譯opencv3:opencv3.3.1+contrib+cuda8.0+vs2013(2015)+cmake3.10.1

cmake編譯opencv3:opencv3.3.1+contrib+cuda8.0+vs2013(2015)+cmake3.10.1

結尾有福利哦!

**

0前言

自從進入3.X時代以後,OpenCV將程式碼庫分成了兩部分,分別是穩定的核心功能庫和試驗性質的contrib庫,而且從3.1以後,編譯好的版本中就沒有現成的x86平臺的庫了,只有x64,想用就必須自己從原始碼編譯。
配置cuda是為了利用GPU的加速。

1安裝所需檔案

cuda之前安裝好了(cuda8.0);

2cmake編譯

1.開啟Cmake

【Where is the source code】放的是OpenCV解壓後的原始碼
我的是 C:\Users\6Qiang\Downloads\opencv-3.3.1

【Where to build the linaries】放的是編譯好的程式
我的是 C:\Users\6Qiang\Downloads\opencv-3.3.1\build
點選【Advanced】按照首字母排序
點選【Configure】之後會進入VS編譯器的版本選擇介面:

注意:

**Win64表示電腦是64位系統,不帶64的表示電腦是Windows 32位系統,ARM表示晶片是ARM的電腦(如Visual Studio 14 2015 Win64)

2.第一次Configure

(第一次Configure一定要聯網,編譯過程中,會下載第三方依賴庫ffmpeg以及ippicv)

  • contrib庫的配置
    找到OPENCV_EXTRRA_MODULES_PATH項,後面新增opencv_contrib-3.3.1中的modules目錄
    (如I:\軟體\專業軟體\opencv_contrib-3.3.1\modules)

  • WITH欄配置
    (WITH_CUDA,WITH_FFT,WITH_CUBLAS應該是預設選中的)
    選中WITH_EIGN,WITH_TBB

注意:

如果不編譯cuda,則搜尋所有包含cuda的專案,然後刪掉其後面的資訊,以免安裝時出現錯誤。

3.第二次configure(不裝cuda則忽略此步驟)

我下載的tbb放在了C:\Users\6Qiang\Downloads\tbb2018_20171205oss

注:此處tbb存放路徑不要有中文,之前我一直編譯錯誤後來發現都是這和中文路徑惹的禍

  • TBB欄配置
    TBB_ENV_iNCLUDE: 新增tbb的include的目錄
    (如C:\Users\6Qiang\Downloads\tbb2018_20171205oss\include)
    TBB_ENV_LIB: 新增tbb的tbb.lib檔案
    (如C:\Users\6Qiang\Downloads\tbb2018_20171205oss\lib\intel64\vc12\tbb.lib)(VS2015就選vc14的目錄

    TBB_ENV_LIB_DEBUG: 新增tbb的tbb_debug.lib檔案
    (如C:\Users\6Qiang\Downloads\tbb2018_20171205oss\lib\intel64\vc12\tbb_debug.lib)(VS2015就選vc14的目錄

4.第三次configure(不斷configure直到最後沒有紅色為止)

TBB_VER_FILE:新增tbb_stddef.h的目錄
(如C:\Users\6Qiang\Downloads\tbb2018_20171205oss\include\tbb\tbb_stddef.h)

5.generate

說明:Cmake中紅色的部分說明還沒有更新,需要點選Configure更新,每次更改完一些配置或者引數之後都要點選Configure更新一下。最後確定配置無誤了再點Generate,將會在你的目標資料夾中生成專案檔案。

6.generate後的顯示

Configuring done
Generating done

3 VS編譯

開啟cmd,轉到自己的編譯後的目錄(我的是C:\Users\6Qiang\Downloads\opencv-3.3.1\build),執行以下命令。

Release模式下編譯:
cmake.exe --build . --config Release --target INSTALL
Debug模式下編譯:
cmake.exe --build . --config Debug --target INSTALL

編譯完成之後,你會在你的目標資料夾中找到一個install資料夾,裡邊就有Debug和Release的各種你需要的東西。(把install資料夾內容複製出來即可)

而沒有cuda的編譯,debug花了13分鐘,release花了18分鐘。
而加入cuda後的編譯,debug、release各花了6個小時左右。

4編譯體會

一共連續搞了5天的編譯,按照網上的步驟一開始各種出錯,後來參考國外部落格的編譯,成功了終於編譯了十幾個多小時,總結出了自己的編譯步驟。

最後,編譯成功了。(沒有錯誤,帶有cuda的一共有9萬多個警告,都是些字元格式警告,不影響)

5vs中的配置

Release版稱為發行版,Debug版稱為除錯版。 Debug中可以單步執行、跟蹤等功能,但生成的可執行檔案比較大,程式碼執行速度較慢。Release版執行速度較快,可執行檔案較小,但在其編譯條件下無法執行除錯功能。

我覺得先用release,遇到問題了再用debug,最後釋出用release(release的速度比debug快很多)。

debug

opencv_aruco331d.lib
opencv_bgsegm331d.lib
opencv_bioinspired331d.lib
opencv_calib3d331d.lib
opencv_ccalib331d.lib
opencv_core331d.lib
opencv_cudaarithm331d.lib
opencv_cudabgsegm331d.lib
opencv_cudacodec331d.lib
opencv_cudafeatures2d331d.lib
opencv_cudafilters331d.lib
opencv_cudaimgproc331d.lib
opencv_cudalegacy331d.lib
opencv_cudaobjdetect331d.lib
opencv_cudaoptflow331d.lib
opencv_cudastereo331d.lib
opencv_cudawarping331d.lib
opencv_cudev331d.lib
opencv_datasets331d.lib
opencv_dnn331d.lib
opencv_dpm331d.lib
opencv_face331d.lib
opencv_features2d331d.lib
opencv_flann331d.lib
opencv_fuzzy331d.lib
opencv_hdf331d.lib
opencv_highgui331d.lib
opencv_imgcodecs331d.lib
opencv_imgproc331d.lib
opencv_img_hash331d.lib
opencv_line_descriptor331d.lib
opencv_ml331d.lib
opencv_objdetect331d.lib
opencv_optflow331d.lib
opencv_phase_unwrapping331d.lib
opencv_photo331d.lib
opencv_plot331d.lib
opencv_reg331d.lib
opencv_rgbd331d.lib
opencv_saliency331d.lib
opencv_shape331d.lib
opencv_stereo331d.lib
opencv_stitching331d.lib
opencv_structured_light331d.lib
opencv_superres331d.lib
opencv_surface_matching331d.lib
opencv_text331d.lib
opencv_tracking331d.lib
opencv_video331d.lib
opencv_videoio331d.lib
opencv_videostab331d.lib
opencv_viz331d.lib
opencv_xfeatures2d331d.lib
opencv_ximgproc331d.lib
opencv_xobjdetect331d.lib
opencv_xphoto331d.lib

release

opencv_aruco331.lib
opencv_bgsegm331.lib
opencv_bioinspired331.lib
opencv_calib3d331.lib
opencv_ccalib331.lib
opencv_core331.lib
opencv_cudaarithm331.lib
opencv_cudabgsegm331.lib
opencv_cudacodec331.lib
opencv_cudafeatures2d331.lib
opencv_cudafilters331.lib
opencv_cudaimgproc331.lib
opencv_cudalegacy331.lib
opencv_cudaobjdetect331.lib
opencv_cudaoptflow331.lib
opencv_cudastereo331.lib
opencv_cudawarping331.lib
opencv_cudev331.lib
opencv_datasets331.lib
opencv_dnn331.lib
opencv_dpm331.lib
opencv_face331.lib
opencv_features2d331.lib
opencv_flann331.lib
opencv_fuzzy331.lib
opencv_hdf331.lib
opencv_highgui331.lib
opencv_imgcodecs331.lib
opencv_imgproc331.lib
opencv_img_hash331.lib
opencv_line_descriptor331.lib
opencv_ml331.lib
opencv_objdetect331.lib
opencv_optflow331.lib
opencv_phase_unwrapping331.lib
opencv_photo331.lib
opencv_plot331.lib
opencv_reg331.lib
opencv_rgbd331.lib
opencv_saliency331.lib
opencv_shape331.lib
opencv_stereo331.lib
opencv_stitching331.lib
opencv_structured_light331.lib
opencv_superres331.lib
opencv_surface_matching331.lib
opencv_text331.lib
opencv_tracking331.lib
opencv_video331.lib
opencv_videoio331.lib
opencv_videostab331.lib
opencv_viz331.lib
opencv_xfeatures2d331.lib
opencv_ximgproc331.lib
opencv_xobjdetect331.lib
opencv_xphoto331.lib

6最後需要把下載的tbb資料夾中的tbb.dll和tbb_debug.dll放到opencv的x64\vc12\bin目錄下(否則可能出現缺少這兩種檔案的錯誤)

我的在C:\Users\6Qiang\Downloads\tbb2018_20171205oss\bin\intel64\vc12下面