Windows下VS2017編譯OpenCV 3.4.0-rc

來源:互聯網
上載者:User

標籤:http   lin   倉庫   msbuild   目錄   完成後   tor   doxygen   files   

簡述

很久沒有用過OpenCV了,這次需要做一點影像處理相關的工作,又需要用起來,這裡記錄一下編譯的過程。之前介紹過使用vs2015編譯opencv2.4的文章在這裡。
編譯好的檔案在這裡https://pan.baidu.com/s/1qXCWxkw

1、下載源碼

這裡就不下載源碼壓縮包了,直接從github上複製一下。

# 因為訪問github較慢,這裡直接使用的國內碼雲同步倉庫git clone https://gitee.com/mirrors/opencv.git# github上的地址為:https://github.com/opencv/opencv.git

複製之後可以將3.4.0-rc分支打包出來,你也可以直接切換到3.4.0-rc分支或者直接使用master的代碼。

cd opencvgit archive -o ../opencv3.4.0.zip 3.4.0-rc

打包出來的壓縮包是不含git倉庫的相關檔案的,不是很大,可以解壓到你想解壓的目錄。

2、使用cmake產生VS工程

我這裡就沒有使用命令列,直接使用的cmake-gui進行的配置。
選擇源碼目錄和構建目錄之後,點擊configure按鈕,然後選擇編譯器為visual studio 2015 2017 win64,等待配置結束。(配置的過程中會去下載opencv_ffmpeg.dll等檔案,過程可能比較慢)

我使用的構建選項改變如下(Tools-->My Changes)

Commandline options:-DBUILD_JAVA:BOOL="0" -DENABLE_LTO:BOOL="1" -DWITH_GSTREAMER:BOOL="0" -DCPACK_BINARY_ZIP:BOOL="1" -DBUILD_TESTS:BOOL="0" -DENABLE_CXX11:BOOL="1" -DBUILD_PERF_TESTS:BOOL="0" -DCPACK_SOURCE_7Z:BOOL="0" -DCPACK_BINARY_NSIS:BOOL="0" Cache file:BUILD_JAVA:BOOL=0ENABLE_LTO:BOOL=1WITH_GSTREAMER:BOOL=0CPACK_BINARY_ZIP:BOOL=1BUILD_TESTS:BOOL=0ENABLE_CXX11:BOOL=1BUILD_PERF_TESTS:BOOL=0CPACK_SOURCE_7Z:BOOL=0CPACK_BINARY_NSIS:BOOL=0

配置輸出資訊如下

General configuration for OpenCV 3.4.0-rc =====================================  Version control:               unknown  Platform:    Timestamp:                   2017-12-20T08:35:12Z    Host:                        Windows 10.0.14393 AMD64    CMake:                       3.7.2    CMake generator:             Visual Studio 15 2017 Win64    CMake build tool:            C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/MSBuild/15.0/Bin/MSBuild.exe    MSVC:                        1912  CPU/HW features:    Baseline:                    SSE SSE2 SSE3      requested:                 SSE3    Dispatched code generation:  SSE4_1 SSE4_2 FP16 AVX AVX2      requested:                 SSE4_1 SSE4_2 AVX FP16 AVX2      SSE4_1 (3 files):          + SSSE3 SSE4_1      SSE4_2 (1 files):          + SSSE3 SSE4_1 POPCNT SSE4_2      FP16 (1 files):            + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX      AVX (5 files):             + SSSE3 SSE4_1 POPCNT SSE4_2 AVX      AVX2 (9 files):            + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2  C/C++:    Built as dynamic libs?:      YES    C++11:                       YES    C++ Compiler:                C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.12.25827/bin/Hostx86/x64/cl.exe  (ver 19.12.25831.0)    C++ flags (Release):         /DWIN32 /D_WINDOWS /W4 /GR  /EHa  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /GL /Oi      /wd4251 /wd4324 /wd4275 /wd4512 /wd4589 /MP4  /MD /O2 /Ob2 /DNDEBUG  /Zi    C++ flags (Debug):           /DWIN32 /D_WINDOWS /W4 /GR  /EHa  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /GL /Oi      /wd4251 /wd4324 /wd4275 /wd4512 /wd4589 /MP4  /D_DEBUG /MDd /Zi /Ob0 /Od /RTC1     C Compiler:                  C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.12.25827/bin/Hostx86/x64/cl.exe    C flags (Release):           /DWIN32 /D_WINDOWS /W3  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /GL /Oi        /MP4  /MD /O2 /Ob2 /DNDEBUG  /Zi    C flags (Debug):             /DWIN32 /D_WINDOWS /W3  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /GL /Oi        /MP4  /D_DEBUG /MDd /Zi /Ob0 /Od /RTC1     Linker flags (Release):      /machine:x64  /LTCG /INCREMENTAL:NO  /debug    Linker flags (Debug):        /machine:x64  /LTCG /debug /INCREMENTAL     ccache:                      NO    Precompiled headers:         YES    Extra dependencies:    3rdparty dependencies:  OpenCV modules:    To be built:                 calib3d core dnn features2d flann highgui imgcodecs imgproc ml objdetect photo python_bindings_generator shape stitching superres ts video videoio videostab    Disabled:                    js world    Disabled by dependency:      -    Unavailable:                 cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev java python2 python3 viz    Applications:                apps    Documentation:               YES (C:/Program Files/doxygen/bin/doxygen.exe 1.8.10)    Non-free algorithms:         NO  Windows RT support:            NO  GUI:     Win32 UI:                    YES    VTK support:                 NO  Media I/O:     ZLib:                        build (ver 1.2.11)    JPEG:                        build (ver 90)    WEBP:                        build (ver encoder: 0x020e)    PNG:                         build (ver 1.6.34)    TIFF:                        build (ver 42 - 4.0.9)    JPEG 2000:                   build (ver 1.900.1)    OpenEXR:                     build (ver 1.7.1)  Video I/O:    Video for Windows:           YES    DC1394:                      NO    FFMPEG:                      YES (prebuilt binaries)      avcodec:                   YES (ver 57.89.100)      avformat:                  YES (ver 57.71.100)      avutil:                    YES (ver 55.58.100)      swscale:                   YES (ver 4.6.100)      avresample:                YES (ver 3.5.0)    DirectShow:                  YES  Parallel framework:            Concurrency  Trace:                         YES (with Intel ITT)  Other third-party libraries:    Intel IPP:                   2017.0.3 [2017.0.3]           at:                   C:/OpenCV/opencv3.4.0/build/3rdparty/ippicv/ippicv_win    Intel IPP IW:                sources (2017.0.3)              at:                C:/OpenCV/opencv3.4.0/build/3rdparty/ippicv/ippiw_win    Lapack:                      NO    Eigen:                       NO    Custom HAL:                  NO  NVIDIA CUDA:                   NO  OpenCL:                        YES (no extra features)    Include path:                C:/OpenCV/opencv3.4.0/3rdparty/include/opencl/1.2    Link libraries:              Dynamic load  Python (for build):            C:/Program Files/Python36/python.exe  Matlab:                        NO  Install to:                    C:/OpenCV/opencv3.4.0/build/install-----------------------------------------------------------------Configuring done

配置完成後點擊Generate按鈕建立VS解決方案即可。

3、編譯

你可以直接進入cmake的構建輸出目錄,雙擊OpenCV.sln使用VS2017開啟,然後構建。
也可以使用命令列進行編譯

# Release版構建命令如下C:\OpenCV\opencv3.4.0\build>msbuild /p:configuration=Release /maxcpucount:4 OpenCV.sln# Debug版本只需要將上面的Release改為Debug即可# 構建完成後,使用下面命令進行安裝(安裝輸出到build下的install目錄,實際上面構建完成就已經安裝)C:\OpenCV\opencv3.4.0\build>msbuild /p:configuration=Release /maxcpucount:4  INSTALL

編譯完成安裝後,即可到build/install目錄下查看相關的標頭檔和庫檔案。

4、遇到的錯誤和解決辦法

1、perl --version錯誤

       “C:\OpenCV\opencv3.4.0\build\OpenCV.sln”(預設目標) (1) ->       “C:\OpenCV\opencv3.4.0\build\doc\doxygen_cpp.vcxproj.metaproj”(預設目標) (50) ->       “C:\OpenCV\opencv3.4.0\build\doc\doxygen_cpp.vcxproj”(預設目標) (52) ->       (CustomBuild 目標) ->         CUSTOMBUILD : error : Problems running bibtex. Verify that the command ‘perl --version‘ works from the command        line. Exit code: 1 [C:\OpenCV\opencv3.4.0\build\doc\doxygen_cpp.vcxproj]    46 個警告    1 個錯誤

這個錯誤與docgen_cpp.vcxproj這個工程相關,那麼是產生文檔相關的,這裡就不該了,直接去掉doxygen文檔產生選項。
在命令列參數中添加-DBUILD_DOCS:BOOL="0"或者在cmake-gui中將BUILD_DOC選中的勾去掉。
然後重新ConfigureGenerate一下。然後重新編譯即可。

Windows下VS2017編譯OpenCV 3.4.0-rc

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.