This is the 11th day of my participation in the August More Text Challenge. For details, see:August is more challenging

Software and Hardware Environment

  • windows 10 64bit
  • nvidia gtx 1070Ti
  • Opencv 4.2.0 – dev
  • Cuda 10.2
  • Cudnn 7.6.5.32
  • visual studio 2019

preface

The goal of this article is to compile the latest source version (4.2.0) of OpencV on a Window10 system, enabling CUDA and CUDNN acceleration. About cuda and cudnn installation on Windows 10, please refer to the previous articles xugaoxiang.com/2019/12/18/… .

Super detailed illustrated tutorial

The first step is to download the source code of opencv and opencv_contrib. We will manage it in a unified directory such as C:\xugaoxiang\opencv_cuda, and create a vs folder to store the compiled files

Next, download the source code

git clone https://github.com/opencv/opencv.git
git clone https://github.com/opencv/opencv_contrib.git
Copy the code

Since OpencV is compiled based on cmake, in order to facilitate the setting of cmake compilation parameters, we go to download cmake and use cmake-gui to configure, the download address is cmake.org/download/

After downloading and installing, we open cmake-gui

Specify the path Where is the source code and Where to build the Binaries, and click the Configure button below

Python2-related errors have occurred and are simply ignored because they were never installed and the version is being deprecated. My Python environment is Anaconda, so don’t forget to set the system environment variables

Next, due to network reasons, there are two download errors, let’s put together, first look at the error message

One is IPPICV and the other is FFMPEG. I tried to download it several times, but it didn’t work. So I have to find another way, according to the error message, open the file opencv\3rdparty\ippicv\ippicv.cmake, find the download address

Note that this link is not the final download address, it needs to be concatenated by first finding the value for ${IPPICV_COMMIT} and then the name of the software package, both of which can be found in the current ippicv.cmake file

The download path of the final package is as follows

Then download the linked file and use your browser

The last thing to do for the downloaded ZIP package is to find the value of OPENCV_ICV_HASH in the ippicv.cmake file and rename the downloaded ZIP package. Get 1 d222685246896fe089f88b8858e4b2f ippicv_2019_win_intel64_20180723_general.zip, copies the file into opencv. Cache \ ippicv

In the same way, we download the missing ffMPEG file and place it in the corresponding directory

So let’s go ahead and download face_landmark_module.dat. This is a file related to face recognition. We’ll download it manually as we did before and put it in the corresponding directory

Continue with Configure, and there is another error

The path of opencv_contrib is not specified. Click Add Entry on cmake-GUI, Add OPENCV_EXTRA_MODULES_PATH, and point to the downloaded opencv_contrib modules folder. Always use/as the directory separator, even on Windows, as shown in the figure below

Due to the installation version of CUDA, we have used the latest 10.2, and some cudA versions do not support errors

Using the grep tool, we find that CUDA_ARCH_BIN is defined in vs/ cmakecache.txt. We directly change the value in this file and remove the small version number

Because of cmake-GUI caching, we also need to change CUDA_ARCH_BIN in cmake-GUI

The rest is smooth until Configure succeeds

To Generate a Visual Studio project, click Generate on cmake-GUI

Next, go to the vs folder, open the file opencv. SLN with Visual Studio 2019, right-click INSTALL under CMakeTargets in the right solution, and select Build

Officially start compiling installation, wait for a while, here I ran close to 2 hours, depending on your computer performance

Finally, go to the opencV installation path to check

You can see that cudA-related DLLS are generated!

summary

In the whole process of compilation and installation, there have been several software package download failed problem, this network environment caused, can only think of another way. To succeed, one must be patient. How to use the compiled OpencV library files? We’ll continue.

The resources

  • Xugaoxiang.com/2019/12/18/…
  • Xugaoxiang.com/2019/12/08/…
  • Github.com/opencv/open…
  • Github.com/opencv/open…
  • www.cnblogs.com/yongy1030/p…