好久沒有用過OpenCV了,此次須要作一點圖像處理相關的工做,又須要用起來,這裏記錄一下編譯的過程。以前介紹過使用vs2015編譯opencv2.4的帖子在這裏。
編譯好的文件在這裏https://pan.baidu.com/s/1qXCWxkwhtml
這裏就不下載源碼壓縮包了,直接從github上克隆一下。java
# 由於訪問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的代碼。python
cd opencv git archive -o ../opencv3.4.0.zip 3.4.0-rc
打包出來的壓縮包是不含git倉庫的相關文件的,不是很大,能夠解壓到你想解壓的目錄。git
我這裏就沒有使用命令行,直接使用的cmake-gui
進行的配置。
選擇源碼目錄和構建目錄以後,點擊configure
按鈕,而後選擇編譯器爲visual studio 2015 2017 win64
,等待配置結束。(配置的過程當中會去下載opencv_ffmpeg.dll等文件,過程可能比較慢)github
我使用的構建選項改變以下(Tools-->My Changes)bash
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=0 ENABLE_LTO:BOOL=1 WITH_GSTREAMER:BOOL=0 CPACK_BINARY_ZIP:BOOL=1 BUILD_TESTS:BOOL=0 ENABLE_CXX11:BOOL=1 BUILD_PERF_TESTS:BOOL=0 CPACK_SOURCE_7Z:BOOL=0 CPACK_BINARY_NSIS:BOOL=0
配置輸出信息以下app
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解決方案便可。ide
你能夠直接進入cmake的構建輸出目錄,雙擊OpenCV.sln
使用VS2017打開,而後構建。
也可使用命令行進行編譯ui
# 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
目錄下查看相關的頭文件和庫文件。spa
一、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
選中的勾去掉。
而後從新Configure
再Generate
一下。而後從新編譯便可。