Easy installation OpenCV Python and CUDA GPU
Sources :
opencv web : https://opencv.org/
opencv github : https://github.com/opencv
youtube tutorial : https://youtu.be/d8Jx6zO1yw0 (Nicolai Nielsen)
In my case,
- I have installed Python 3.9.12
- Opencv 4.6.0
- Opencv-contrib 4.6.0
- CUDA version 11.2
Follow this step carefully (this step installation is for windows) :
-
Download and install NVIDIA-CUDA here
-
Install Cmake, you can download here and choose windows x64 installer or you can just click here to download Cmake installation directly.
-
Download and extract opencv 4.6.0 source code here or you can try to download other version shown below.
-
Download and extract opencv_contrib 4.6.0 here, remember to download the same version in opencv source code and contrib file.
-
Create folder "opencvGPU" in your local computer, in my case I create it on local disk C:\opencvGPU. Put opencv-4.6.0 and opencv_contrib-4.6.0 in this folder and create 'build' folder. We have empty 'build' folder, this folder will be a place for cmake to build the binaries. Do the same as picture below.
- After it's done, click configure and pop up will show up. need to install Visual Studio 16 (or Visual Studio 2019), you can download it here. Put the same form as below then finish.
- After that wait untill finish the configuration for the first time. And then set different kind of flags (type on search to find it quick) such as :
- WITH_CUDA (checklist)
- ENABLE_FAST_MATH (checklist)
- BUILD_opencv_world (checklist)
- OPENCV_EXTRA_MODULES_PATH (select directory of opencv-contrib modules, C:\opencvGPU\opencv_contrib-4.6.0\modules
- And then click configure again and wait in several minutes.
- After that, set several flags again.
- CUDA_FAST_MATH (checklist)
- CUDA_ARCH_BIN (6.1), you can check compute capability of NVIDIA GPU here and click CUDA-Enabled GeForce and TITAN Products, in this case I'm using NVIDIA GeForce GTX 1050 so the compute capability is 6.1, if you have more than 1 GPU so put more than 1 value for CUDA_ARCH_BIN e.g (6.1;8.6:and soon).
- CMAKE_CONFIGURATION_TYPES (Release)
- Then click Configure for the last time, wait till done.
-
After that, open "command prompt" and type command to install : cmake --build "C:\your_path\build" --target INSTALL --config Release,
example : Command to Install: cmake --build "C:\opencvGPU\build" --target INSTALL --config Release, press ENTER and the command will run the program to build the binaries files into build directory. It takes 1-2 hours depend on your laptop. Maybe you will face some error and warning but as long as the installation is still working so don't worry about it just continue it. -
After finish building the binaries, open cmd again and type the same as below :