Win10 + VS2022 + OpenCV 4.7 + contrib + cuda accelerated compilation

Compiled:

https://download.csdn.net/download/Kasper_2009/88252429icon-default.png?t=N6B9https://download.csdn.net/download/Kasper_2009/88252429

1. Preparation

1. cuda installation

Type nvidia-smi in the cmd command to see the highest version of cuda supported

The choice of cuda version should not be too early. The author has used cuda11.2 before, and found that it only supports vs2019 and does not support vs2022 in the follow-up vs compilation link. Currently the author uses cuda11.8.

Download and install cuda: CUDA Toolkit Archive | NVIDIA Developer

2. cuDNN download configuration

Download and configure cuDNN corresponding to the cuda version: cuDNN Archive | NVIDIA Developer

Copy the three folders (bin, include, lib) decompressed by cuDNN to the corresponding folder with the same name of cuda (the default installation path is C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v[version number]), Win10 will automatically merge the content inside accordingly.

3. cmake download and install

Download | CMake

4. Download and install Visual Studio 2022

Visual Studio: IDE and Code Editor for Software Developers and Teams (microsoft.com)

5. OpenCV and the corresponding contrib package source code download

OpenCV GitHub  (there is a ladder to connect more stable)

Click on the two cards to download the source code of the desired version, pay attention to the branch selection in the upper left corner, click the code to download Download ZIP, you don’t have to use git get. . .

Two, cmake generation project

1. Configure for the first time

Open cmake-gui (if you can't find it, search in the search box next to the start menu), fill in the location of the opencv source code and the location of the build folder (new):

 Click Configure, select the vs2022 and x64 platforms, and start the first Configure after confirming

2. The second Configure

After the first Configure, search and configure some options in the search box:

  • Check BUILD_opencv_world (you only need to configure opencv_world470.lib or opencv_world470d.lib in subsequent projects, otherwise you have to configure each separate package)
  • Configure OPENCV_EXTRA_MODULES_PATH, fill in the location of the contrib source folder
  • Search for "cuda", check BUILD_CUDA_STUBS, OPENCV_DNN_CUDA, WITH_CUDA
  • Tick ​​ENABLE_FAST_MATH 
  • Tick ​​OPENCV_ENABLE_NONFREE
  • Uncheck OpenCV_GENERATE_SETUPVARS
  • Search for "python", "java", "js", and "tests" respectively, and uncheck all the options related to python, java, js, and tests that have been checked

Click Configure for the second Configure

3. The third Configure and Generate generation project

After the second Configure, there are some new options that need to be configured:

  • Tick ​​CUDA_FAST_MATH
  • CUDA_ARCH_BIN Fill in the computing power index of the corresponding GPU. If there are multiple values, you can delete other values ​​to speed up subsequent compilation. The computing power index query link: CUDA GPUs - Compute Capability | NVIDIA Developer

Click Configure for the third Configure, click Generate to generate the project

Three, vs2022 compilation

After the above step Generate, click Open Project directly on the cmake-gui to open the vs project

1. Select Release (or Debug) and x64 platform

2. Right-click the ALL_BUILD project and click Generate

3. Right-click the INSTALL project, click Only for project -> Generate INSTALL only

At this point, the compilation is complete, and the product is in the install folder under the build folder specified when configuring cmake in the above step 2

Guess you like

Origin blog.csdn.net/Kasper_2009/article/details/130384029
Recommended