||
Working in the field of Computer Vision for a decade, I have been using popular application frameworks to help me accomplish complex tasks, such as image processing, object tracking, face detection, and more.
Two of these tools are OpenCV and CUDA.
OpenCV is a set of programming modules that help us accomplish complex real-time computer vision tasks easily. Due to its reliability and open-source philosophy, it’s been one of the most popular computer vision tools.
CUDA is a parallel computing toolkit that allows us to use the power of an NVidia GPU to significantly accelerate the performance of our applications.
James Bowley has published a detailed performance comparison, where you can see the impact of CUDA on OpenCV.
However, the official OpenCV binaries do not include GPU support out-of-the-box. To harness the full power of your GPU, you’ll need to build the library yourself.
So, in the following guide will show you how to compile OpenCV with CUDA support.
For your convenience, I have uploaded the latest stable compiled binaries.
Remember: if you download the binaries, share this post to help other developers, too!
Ensure you have a computer with the following specifications:
GPU with CUDA support (tested on Nvidia 1060)
CPU Intel Core i7 (recommended)
Download and install the following software:
Visual Studio 2015 Community or Professional
Nvidia CUDA download page:
Nvidia cuDNN download page:
This is how to download and compile the latest version of OpenCV with CUDA support.
Clone OpenCV to the desired location in your disk:
git clone https://github.com/opencv/opencv.git
In my case:
C:\Users\Vangos\Projects\OpenCV
Also, switch to switch to the latest stable branch, e.g. “3.4”.
Before going on, ensure that your Path Environment Variable includes the following path:
C:\Program Files (x86)\Windows Kits\8.1\bin\x64
In case the path is not included, add it manually.
Open CMD and type the following command. Replace PATH_TO_SOURCE with the path of the OpenCV installation (e.g. C:\Users\Vangos\Projects\OpenCV).
"C:\Program Files\CMake\bin\cmake.exe" -B"PATH_TO_SOURCE\build" -H"PATH_TO_SOURCE" -G"Visual Studio 14 2015 Win64" -DBUILD_opencv_world=ON -DWITH_CUDA=ON -DCUDA_FAST_MATH=ON -DWITH_CUBLAS=ON -DINSTALL_TESTS=ON -DINSTALL_C_EXAMPLES=ON -DBUILD_EXAMPLES=ON
In my case:
"C:\Program Files\CMake\bin\cmake.exe" -B"C:\Users\Vangos\Projects\OpenCV\build" -H"C:\Users\Vangos\Projects\OpenCV" -G"Visual Studio 14 2015 Win64" -DBUILD_opencv_world=ON -DWITH_CUDA=ON -DCUDA_FAST_MATH=ON -DWITH_CUBLAS=ON -DINSTALL_TESTS=ON -DINSTALL_C_EXAMPLES=ON -DBUILD_EXAMPLES=ON
Navigate to the PATH_TO_SOURCE folder and open the build directory. Find the OpenCV.sln file and open it with Visual Studio 2015.
In the Configuration Manager, select the following:
Active solution configuration: Release
Active solution platform: x64
In your Solution Explorer, find the project named INSTALL.
Right-click the INSTALL project and select “Build”.
Then, wait patiently while Visual Studio builds the project. Depending on your computer specs, it may take lots of minutes or even hours!
When the compilation process is finished, the binaries should be under the build\install directory.
You can now follow the official OpenCV guide and integrate OpenCV with CUDA support in your own applications!
When running your OpenCV projects using Visual Studio, you need to add the following information in your Project Properties window:
C/C++ → General → Additional Include Directories
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.1\include
and
C:\Users\Vangos\Projects\OpenCV\build\install\include
Linker → General → Additional Library Directories
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.1\lib\x64
and
C:\Users\Vangos\Projects\OpenCV\build\install\x64\vc14\lib
Linker → General → Additional Dependencies
opencv_world400.lib
and
cudnn.lib
This is it! You can now use the full power of a GPU-accelerated OpenCV build.
Again, if you just want the precompiled binaries, I have uploaded them for you. Before downloading, please do me a favor and share this post on social media. This way, you are going to help other developers access great resources.
So, did you find this tutorial helpful? How are you going to use OpenCV with GPU CUDA support? Let me know in the comments below!
Sources:
https://pterneas.com/2018/11/02/opencv-cuda/
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-11-30 00:37
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社