OpenCV - Windows(win10)編譯opencv + opencv_contrib


  在之前的幾篇文章中,我提到了在Android、Linux中編譯opencv + opencv_contrib,這篇文章主要講在Windows中編譯opencv + opencv_contrib。

首先需要准備的環境有:

  將下載得到的OpenCV Windows包解壓,目錄為opencv,然后將下載的OpenCV_Contrib包解壓放入opencv目錄下,新建new_build文件夾(用來放編譯之后結果):

    

使用cmake生成OpenCV.sln:

  打開安裝之后的cmake,在where is the source code中選擇openCV的源代碼目錄:F:\opencv\sources;在where to build the binaries中選擇編譯為Visual Studio項目的目錄:F:\opencv\new_build(這里我選擇剛剛特地建立的new_build目錄),如下圖所示:

    

  點擊Configure按鈕后,彈出對話框,選擇編譯器,根據本地計算機的CPU架構,這里特別要注意的是,自己機器上是否裝有相應的VS版本,如果沒有裝,還是要編譯就會出錯,可能是找不到對應的工具原因,以及選擇X86和X64),這里用的是VS 2015。

    

  設置完成之后點擊“Generate”開始生成工程,.第一次編譯完成之后,我們需要將額外的opencv_contrib加到工程中進行第二次編譯,在配置表中找到“OPENCV_EXTRA_MODULES_PATH”,設置其參數值為open_contrib源碼包中的modles目錄,我的目錄是“F:\opencv\opencv_contrib\modules”:

    

  再次點擊“Generate”進行第二次編譯:

    

  這時候我們已經可以看見用cmake工具編譯得到的OpenCV.sln:

    

用VS打開OpenCV.sln工程,編譯生成Debug和Release庫:

  用VS 2015打開OpenCV.sln工程,在解決方案中可以查看工程目錄:

    

  編譯生成debug版本的庫,記得在此之前要選擇編譯的平台信息,這就是編譯生成debug版本和release版本的區別,也可以選擇release,因為自己的工程可能要用到相應的動態鏈接庫:

    

  在解決方案中選中工程,右鍵選擇重新生成解決方案:

    

  編譯成功:

    

  .找到CMakeTargets中的INSTALL,然后右鍵選擇“僅限於項目”-->“僅生成INSTALL”:

    

  完成編譯后,Release模式下同理。此時,有了install目錄。該目錄包含了我們需要的頭文件、庫文件。

    

把新的庫文件配置到到項目中:

   VC++目錄-->包含目錄,添加:

    E:\OpenCV320\opencv\new_build\install\include

  VC++目錄-->庫目錄,添加:

    E:\OpenCV320\opencv\new_build\install\x64\vc14\lib

  鏈接器-->輸入-->附加依賴項,添加: (注意添加的庫與編譯選項要一致,需要注意debug比release的文件名多了個d)

    opencv_aruco320.lib

    opencv_aruco320d.lib

    opencv_bgsegm320.lib
    opencv_bgsegm320d.lib
    opencv_bioinspired320.lib
    opencv_bioinspired320d.lib
    opencv_calib3d320.lib
    opencv_calib3d320d.lib
    opencv_ccalib320.lib
    opencv_ccalib320d.lib
    opencv_core320.lib
    opencv_core320d.lib
    opencv_datasets320.lib
    opencv_datasets320d.lib
    opencv_dnn320.lib
    opencv_dnn320d.lib
    opencv_dpm320.lib
    opencv_dpm320d.lib
    opencv_face320.lib
    opencv_face320d.lib
    opencv_features2d320.lib
    opencv_features2d320d.lib
    opencv_flann320.lib
    opencv_flann320d.lib
    opencv_fuzzy320.lib
    opencv_fuzzy320d.lib
    opencv_highgui320.lib
    opencv_highgui320d.lib
    opencv_imgcodecs320.lib
    opencv_imgcodecs320d.lib
    opencv_line_descriptor320.lib
    opencv_line_descriptor320d.lib
    opencv_ml320.lib
    opencv_ml320d.lib
    opencv_objdetect320.lib
    opencv_objdetect320d.lib
    opencv_optflow320.lib
    opencv_optflow320d.lib
    opencv_phase_unwrapping320.lib
    opencv_phase_unwrapping320d.lib
    opencv_photo320.lib
    opencv_photo320d.lib
    opencv_plot320.lib
    opencv_plot320d.lib
    opencv_reg320.lib
    opencv_reg320d.lib
    opencv_rgbd320.lib
    opencv_rgbd320d.lib
    opencv_saliency320.lib
    opencv_saliency320d.lib
    opencv_shape320.lib
    opencv_shape320d.lib
    opencv_stereo320.lib
    opencv_stereo320d.lib
    opencv_stitching320.lib
    opencv_stitching320d.lib
    opencv_structured_light320.lib
    opencv_structured_light320d.lib
    opencv_superres320.lib
    opencv_superres320d.lib
    opencv_surface_matching320.lib
    opencv_surface_matching320d.lib
    opencv_text320.lib
    opencv_text320d.lib
    opencv_tracking320.lib
    opencv_tracking320d.lib
    opencv_video320.lib
    opencv_video320d.lib
    opencv_videoio320.lib
    opencv_videoio320d.lib
    opencv_videostab320.lib
    opencv_videostab320d.lib
    opencv_xfeatures2d320.lib
    opencv_xfeatures2d320d.lib
    opencv_ximgproc320.lib
    opencv_ximgproc320d.lib
    opencv_xobjdetect320.lib
    opencv_xobjdetect320d.lib
    opencv_xphoto320.lib
    opencv_xphoto320d.lib
    kernel32.lib
    user32.lib
    gdi32.lib
    winspool.lib
    comdlg32.lib
    advapi32.lib
    shell32.lib
    ole32.lib
    oleaut32.lib
    uuid.lib
    odbc32.lib
    odbccp32.lib

  這樣,我們就可以在VS中使用OpenCV了。

 

  需要提到的一個點,所需要使用Sift等算法,需要引入xfeatures2d命名空間:

using namespace xfeatures2d;

 

   


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM