Win10 + Microsoft Visual Studio Community 2017 + CUDA11.3 + CUDNN8.2 + RTX GeForce 3090 + OpenCV4.5.3
前往官网下载Visual Studio Installer即可,做如下勾选,安装即可
完成后,查看环境变量,将MSVC编译器地址加入环境变量
D:\programming\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\Hostx64\x64
前往官网下载CUDA和对应的CUDNN,切记一定要对应CUDNN和CUDA版本,根据提示一步一步安装即可,完成后将CUDNN解压,替换C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.3
下的对应文件
进入OpenCV官网,选择自己需要的版本,例如OpenCV-4.5.3
进入OpenCV GitHub官方仓库,通过tags选择对应的contrib版本
进入CMake官网,下载最新版就行,我这里下载的CMake 3.24.0-rc4
中间需要多次点击”configure“
(1) BUILD_opencv_world
勾选 BUILD_opencv_world:此项的目的是生成一个dll文件,比如:opencv_world430d.dll。
(2) OPENCV_DNN_CUDA
勾选OPENCV_DNN_CUDA
(3)OPENCV_ENABLE_NONFREE
勾选 OPENCV_ENABLE_NONFREE:此项目的是编译contrib模块。
(4) OPENCV_EXTRA_MODULES_PATH
设置OPENCV_EXTRA_MODULES_PATH:设置contrib模块的目录:(注意一定到modules这个目录)
(5) WITH_CUDA
勾选WITH_CUDA。
(6) CUDA_ARCH_BIN
设置自己的算力大小,参考这里,我这里设置是8.6。如果查不到此项,请configure一次。
(7) WITH_CUDNN
勾选 WITH_CUDNN。如果查不到此项,请configure一次。
(8) CUDA_FAST_MATH
勾选CUDA_FAST_MATH。
(9) python和java相关组件
如果不使用python和java就将如下python和java相关的对应项的”√“去掉。(因版本不同,组件名称不一定一样,请根据实际选择)
(10) 其他
其他的选项就根据自己喜好设定,比如test模块等。
以上经过多次点击”Configure“,确定没有任何错误提示信息。
等待Configure完成之后,查看是否检测到了CUDA和cuDNN,都出现YES之后,说明没有问题。如果没有检测到的话,需要确认是否CUDA和cuDNN版本正确,否则后面的编译将不会编译CUDA模块,白白浪费时间。确认之后,点击Generate,最终如下所示:
Selecting Windows SDK version 10.0.17763.0 to target Windows 10.0.19043.
Detected processor: AMD64
libjpeg-turbo: VERSION = 2.1.0, BUILD = opencv-4.5.3-libjpeg-turbo
Could NOT find OpenJPEG (minimal suitable version: 2.0, recommended version >= 2.3.1). OpenJPEG will be built from sources
OpenJPEG: VERSION = 2.4.0, BUILD = opencv-4.5.3-openjp2-2.4.0
OpenJPEG libraries will be built from sources: libopenjp2 (version "2.4.0")
found Intel IPP (ICV version): 2020.0.0 [2020.0.0 Gold]
at: H:/programming/opencvbuild/3rdparty/ippicv/ippicv_win/icv
found Intel IPP Integration Wrappers sources: 2020.0.0
at: H:/programming/opencvbuild/3rdparty/ippicv/ippicv_win/iw
CUDA detected: 11.3
CUDA: Using CUDA_ARCH_BIN=8.6
CUDA NVCC target flags: -gencode;arch=compute_86,code=sm_86;-D_FORCE_INLINES
CUDA: MSVS generator is detected. Disabling CMake re-run checks (CMAKE_SUPPRESS_REGENERATION=ON). You need to run CMake manually if updates are required.
Could not find OpenBLAS include. Turning OpenBLAS_FOUND off
Could not find OpenBLAS lib. Turning OpenBLAS_FOUND off
Could NOT find BLAS (missing: BLAS_LIBRARIES)
Could NOT find LAPACK (missing: LAPACK_LIBRARIES)
Reason given by package: LAPACK could not be found because dependency BLAS could not be found.
VTK is not found. Please set -DVTK_DIR in CMake to VTK build directory, or to VTK install subdirectory with VTKConfig.cmake file
Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE)
OpenCV Python: during development append to PYTHONPATH: H:/programming/opencvbuild/python_loader
Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE)
Module opencv_alphamat disabled because the following dependencies are not found: Eigen
freetype2: NO
harfbuzz: NO
Julia not found. Not compiling Julia Bindings.
Module opencv_ovis disabled because OGRE3D was not found
No preference for use of exported gflags CMake configuration set, and no hints for include/library directories provided. Defaulting to preferring an installed/exported gflags CMake configuration if available.
Failed to find installed gflags CMake configuration, searching for gflags build directories exported with CMake.
Failed to find gflags - Failed to find an installed/exported CMake configuration for gflags, will perform search for installed gflags components.
Failed to find gflags - Could not find gflags include directory, set GFLAGS_INCLUDE_DIR to directory containing gflags/gflags.h
Failed to find glog - Could not find glog include directory, set GLOG_INCLUDE_DIR to directory containing glog/logging.h
Module opencv_sfm disabled because the following dependencies are not found: Eigen Glog/Gflags
Tesseract: NO
Processing WORLD modules...
module opencv_cudev...
module opencv_core...
Allocator metrics storage type: 'long long'
module opencv_cudaarithm...
module opencv_flann...
module opencv_imgproc...
module opencv_intensity_transform...
module opencv_ml...
module opencv_phase_unwrapping...
module opencv_plot...
module opencv_quality...
module opencv_reg...
module opencv_surface_matching...
module opencv_cudafilters...
module opencv_cudaimgproc...
module opencv_cudawarping...
module opencv_dnn...
Registering hook 'INIT_MODULE_SOURCES_opencv_dnn': H:/programming/opencv/sources/modules/dnn/cmake/hooks/INIT_MODULE_SOURCES_opencv_dnn.cmake
module opencv_dnn_superres...
module opencv_features2d...
module opencv_fuzzy...
module opencv_hfs...
module opencv_imgcodecs...
module opencv_line_descriptor...
module opencv_photo...
module opencv_saliency...
module opencv_text...
module opencv_videoio...
module opencv_wechat_qrcode...
module opencv_xphoto...
module opencv_barcode...
module opencv_calib3d...
module opencv_cudacodec...
module opencv_cudafeatures2d...
module opencv_cudastereo...
module opencv_datasets...
module opencv_highgui...
highgui: using builtin backend: WIN32UI
module opencv_mcc...
module opencv_objdetect...
module opencv_rapid...
module opencv_rgbd...
rgbd: Eigen support is disabled. Eigen is Required for Posegraph optimization
module opencv_shape...
module opencv_structured_light...
module opencv_video...
module opencv_xfeatures2d...
module opencv_ximgproc...
module opencv_xobjdetect...
module opencv_aruco...
module opencv_bgsegm...
module opencv_bioinspired...
module opencv_ccalib...
module opencv_cudabgsegm...
module opencv_cudalegacy...
module opencv_cudaobjdetect...
module opencv_dnn_objdetect...
module opencv_dpm...
module opencv_face...
module opencv_gapi...
module opencv_optflow...
module opencv_stitching...
module opencv_tracking...
module opencv_cudaoptflow...
Building with NVIDIA Optical Flow API 2.0
module opencv_stereo...
module opencv_superres...
module opencv_videostab...
Processing WORLD modules... DONE
General configuration for OpenCV 4.5.3 =====================================
Version control: unknown
Extra modules:
Location (extra): H:/programming/opencv_contrib-4.5.3/modules
Version control (extra): unknown
Platform:
Timestamp: 2022-07-27T05:51:33Z
Host: Windows 10.0.19043 AMD64
CMake: 3.24.0-rc4
CMake generator: Visual Studio 15 2017
CMake build tool: D:/programming/Microsoft Visual Studio/2017/Community/MSBuild/15.0/Bin/MSBuild.exe
MSVC: 1916
Configuration: Debug Release
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 (17 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 (31 files): + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
AVX512_SKX (7 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++ standard: 11
C++ Compiler: D:/programming/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x64/cl.exe (ver 19.16.27045.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 /MP /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 /MP /MDd /Zi /Ob0 /Od /RTC1
C Compiler: D:/programming/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/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 /Oi /fp:precise /MP /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 /MP /MDd /Zi /Ob0 /Od /RTC1
Linker flags (Release): /machine:x64 /INCREMENTAL:NO
Linker flags (Debug): /machine:x64 /debug /INCREMENTAL
ccache: NO
Precompiled headers: NO
Extra dependencies: cudart_static.lib nppc.lib nppial.lib nppicc.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/v11.3/lib/x64
3rdparty dependencies:
OpenCV modules:
To be built: aruco barcode 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 hfs highgui img_hash imgcodecs imgproc intensity_transform line_descriptor mcc ml objdetect optflow phase_unwrapping photo plot quality rapid reg rgbd saliency shape stereo stitching structured_light superres surface_matching text tracking ts video videoio videostab wechat_qrcode world xfeatures2d ximgproc xobjdetect xphoto
Disabled: java_bindings_generator python_bindings_generator python_tests
Disabled by dependency: -
Unavailable: alphamat cvv freetype hdf java julia matlab ovis python2 python3 sfm viz
Applications: tests perf_tests apps
Documentation: NO
Non-free algorithms: YES
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.1.0-62)
WEBP: build (ver encoder: 0x020f)
PNG: build (ver 1.6.37)
TIFF: build (ver 42 - 4.2.0)
JPEG 2000: build (ver 2.4.0)
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.134.100)
avformat: YES (58.76.100)
avutil: YES (56.70.100)
swscale: YES (5.9.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: 2020.0.0 Gold [2020.0.0]
at: H:/programming/opencvbuild/3rdparty/ippicv/ippicv_win/icv
Intel IPP IW: sources (2020.0.0)
at: H:/programming/opencvbuild/3rdparty/ippicv/ippicv_win/iw
Lapack: NO
Eigen: NO
Custom HAL: NO
Protobuf: build (3.5.1)
NVIDIA CUDA: YES (ver 11.3, CUFFT CUBLAS FAST_MATH)
NVIDIA GPU arch: 86
NVIDIA PTX archs:
cuDNN: YES (ver 8.2.1)
OpenCL: YES (NVD3D11)
Include path: H:/programming/opencv/sources/3rdparty/include/opencl/1.2
Link libraries: Dynamic load
Python (for build): D:/programming/anaconda3/python.exe
Install to: H:/programming/opencvbuild/install
-----------------------------------------------------------------
Configuring done
ALL_BUILD,点击“Open Project”打开工程,在Release模式下右键点击ALL_BUILD,生成,时间较长(i7-11700k大概60分钟)
生成之后,右击INSTALL->仅用于项目->仅生成INSTALL
完成后,install文件夹就是我们需要的,至此就完成了OpenCV-CUDA的编译安装