Windows下CMake编译OpenCV 4.1.2+contrib + CUDA

ENV

  • CMake 3.16.0
  • Visual Studio 2019
  • Windows 10 1909
  • CUDA 10.2.89 + CUDNN 7.6.5
  • OpenCV 4.1.2
  • opencv_contrib 4.1.2
  • Python 3.7.4
  • Core i7 9700K + RTX 2080

Eigen(可选)

Eigen官网

Compile

# 注意替换命令中的安装路径和contrib的路径
 cmake -A x64 -DCMAKE_INSTALL_PREFIX= -DOPENCV_EXTRA_MODULES_PATH=/opencv_contrib/modules -DBUILD_DOCS=OFF -DWITH_CUDA=ON -DCUDA_FAST_MATH=ON -DCUDA_GENERATION=Auto -DWITH_TBB=ON -DBUILD_opencv_python2=OFF -DBUILD_opencv_python3=ON ..

# Debug
cmake --build . -j 8 --config Debug --target install 
# Release
cmake --build . -j 8 --config Release --target install 

CUDA_GENERATION=Auto选项会针对本地GPU生成代码(否则生成所有支持架构的代码),可以加快编译速度。

针对CMake生成过程中下载库失败的问题

例如:以ffmpeg的动态库为例说明

  • opencv_videoio_ffmpeg.dll
  • opencv_videoio_ffmpeg_64.dll
  • ffmpeg_version.cmake

找到opencv/3rdparty/ffmpeg/ffmpeg.cmake文件,定位到https下载链接这一行

https://raw.githubusercontent.com/opencv/opencv_3rdparty/${FFMPEG_BINARIES_COMMIT}/ffmpeg/

FFMPEG_BINARIES_COMMIT替换为文件顶部定义的值197f87f7e811a9ded35d989b37e50501ff6afaa4,并添加下载文件名,
最终下载链接为:

https://raw.githubusercontent.com/opencv/opencv_3rdparty/197f87f7e811a9ded35d989b37e50501ff6afaa4/ffmpeg/opencv_videoio_ffmpeg.dll

粘贴到浏览器下载,其他几个文件同理。
最后,将ffmpeg.cmake文件中https下载链接替换为文件下载地址:

 file:///D:/Code/libraries/opencv_downloads/

再次用cmake生成工程就可以了。

CMake configuration

--
-- General configuration for OpenCV 4.1.2 =====================================
--   Version control:               unknown
--
--   Extra modules:
--     Location (extra):            D:/Code/libraries/opencv_contrib/modules
--     Version control (extra):     unknown
--
--   Platform:
--     Timestamp:                   2019-12-06T06:13:26Z
--     Host:                        Windows 10.0.18363 AMD64
--     CMake:                       3.16.0
--     CMake generator:             Visual Studio 16 2019
--     CMake build tool:            C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/MSBuild/Current/Bin/MSBuild.exe
--     MSVC:                        1923
--
--   CPU/HW features:
--     Baseline:                    SSE SSE2 SSE3
--       requested:                 SSE3
--     Dispatched code generation:  SSE4_1 SSE4_2 FP16 AVX AVX2 AVX512_SKX
--       requested:                 SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
--       SSE4_1 (16 files):         + SSSE3 SSE4_1
--       SSE4_2 (2 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 (29 files):           + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
--       AVX512_SKX (6 files):      + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2 AVX_512F AVX512_COMMON AVX512_SKX
--
--   C/C++:
--     Built as dynamic libs?:      YES
--     C++ Compiler:                C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.23.28105/bin/Hostx64/x64/cl.exe  (ver 19.23.28107.0)
--     C++ flags (Release):         /DWIN32 /D_WINDOWS /W4 /GR  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:precise     /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589 /MP8   /MD /O2 /Ob2 /DNDEBUG
--     C++ flags (Debug):           /DWIN32 /D_WINDOWS /W4 /GR  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:precise     /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589 /MP8   /MDd /Zi /Ob0 /Od /RTC1
--     C Compiler:                  C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.23.28105/bin/Hostx64/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 /Oi  /fp:precise       /MP8    /MD /O2 /Ob2 /DNDEBUG
--     C flags (Debug):             /DWIN32 /D_WINDOWS /W3  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:precise       /MP8  /MDd /Zi /Ob0 /Od /RTC1
--     Linker flags (Release):      /machine:x64  /INCREMENTAL:NO
--     Linker flags (Debug):        /machine:x64  /debug /INCREMENTAL
--     ccache:                      NO
--     Precompiled headers:         YES
--     Extra dependencies:          cudart_static.lib nppc.lib nppial.lib nppicc.lib nppicom.lib nppidei.lib nppif.lib nppig.lib nppim.lib nppist.lib nppisu.lib nppitc.lib npps.lib cublas.lib cudnn.lib cufft.lib -LIBPATH:C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.2/lib/x64
--     3rdparty dependencies:
--
--   OpenCV modules:
--     To be built:                 aruco bgsegm bioinspired calib3d ccalib core cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev datasets dnn dnn_objdetect dnn_superres dpm face features2d flann fuzzy gapi hdf hfs highgui img_hash imgcodecs imgproc line_descriptor ml objdetect optflow phase_unwrapping photo plot python3 quality reg rgbd saliency sfm shape stereo stitching structured_light superres surface_matching text tracking ts video videoio videostab xfeatures2d ximgproc xobjdetect xphoto
--     Disabled:                    world
--     Disabled by dependency:      -
--     Unavailable:                 cnn_3dobj cvv freetype java js matlab ovis python2 viz
--     Applications:                tests perf_tests apps
--     Documentation:               NO
--     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-libjpeg-turbo (ver 2.0.2-62)
--     WEBP:                        build (ver encoder: 0x020e)
--     PNG:                         build (ver 1.6.37)
--     TIFF:                        build (ver 42 - 4.0.10)
--     JPEG 2000:                   build (ver 1.900.1)
--     OpenEXR:                     build (ver 2.3.0)
--     HDR:                         YES
--     SUNRASTER:                   YES
--     PXM:                         YES
--     PFM:                         YES
--
--   Video I/O:
--     DC1394:                      NO
--     FFMPEG:                      YES (prebuilt binaries)
--       avcodec:                   YES (58.54.100)
--       avformat:                  YES (58.29.100)
--       avutil:                    YES (56.31.100)
--       swscale:                   YES (5.5.100)
--       avresample:                YES (4.0.0)
--     GStreamer:                   NO
--     DirectShow:                  YES
--     Media Foundation:            YES
--       DXVA:                      YES
--
--   Parallel framework:            Concurrency
--
--   Trace:                         YES (with Intel ITT)
--
--   Other third-party libraries:
--     Intel IPP:                   2019.0.0 Gold [2019.0.0]
--            at:                   D:/Code/libraries/opencv-4.1.2/build/3rdparty/ippicv/ippicv_win/icv
--     Intel IPP IW:                sources (2019.0.0)
--               at:                D:/Code/libraries/opencv-4.1.2/build/3rdparty/ippicv/ippicv_win/iw
--     Lapack:                      NO
--     Eigen:                       YES (ver 3.3.7)
--     Custom HAL:                  NO
--     Protobuf:                    build (3.5.1)
--
--   NVIDIA CUDA:                   YES (ver 10.2, CUFFT CUBLAS FAST_MATH)
--     NVIDIA GPU arch:             75
--     NVIDIA PTX archs:
--
--   cuDNN:                         YES (ver 7.6.5)
--
--   OpenCL:                        YES (NVD3D11)
--     Include path:                D:/Code/libraries/opencv-4.1.2/3rdparty/include/opencl/1.2
--     Link libraries:              Dynamic load
--
--   Python 3:
--     Interpreter:                 C:/ProgramData/Anaconda3/python.exe (ver 3.7.4)
--     Libraries:                   C:/ProgramData/Anaconda3/libs/python37.lib (ver 3.7.4)
--     numpy:                       C:/ProgramData/Anaconda3/lib/site-packages/numpy/core/include (ver 1.16.5)
--     install path:                C:/ProgramData/Anaconda3/Lib/site-packages/cv2/python-3.7
--
--   Python (for build):            C:/ProgramData/Anaconda3/python.exe
--
--   Java:
--     ant:                         NO
--     JNI:                         NO
--     Java wrappers:               NO
--     Java tests:                  NO
--
--   Install to:                    D:/Libs/opencv
-- -----------------------------------------------------------------

你可能感兴趣的:(opencv,图像处理)