jingweimo的个人博客分享 http://blog.sciencenet.cn/u/jingweimo

博文

[转载]Build OpenCV for CUDA support

已有 2546 次阅读 2019-1-10 07:27 |系统分类:科研笔记|文章来源:转载

 

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.

Download OpenCV CUDA binaries

Remember: if you download the binaries, share this post to help other developers, too!

System Requirements

Hardware

Ensure you have a computer with the following specifications:

  • GPU with CUDA support (tested on Nvidia 1060)

  • CPU Intel Core i7 (recommended)

Software

Download and install the following software:

Nvidia CUDA download page:

NVidia CUDA 9.1 download page

Nvidia cuDNN download page:
NVidia CuDNN 7.1 download page

Build/Compile OpenCV

This is how to download and compile the latest version of OpenCV with CUDA support.

1) Clone OpenCV

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”.
OpenCV repository

2) Generate the Visual Studio solution

Before going on, ensure that your Path Environment Variable includes the following path:

C:\Program Files (x86)\Windows Kits\8.1\bin\x64

Environment Variables - Windows Kits

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

3) Compile!

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

Visual Studio Configuration Manager - OpenCV CUDA

In your Solution Explorer, find the project named INSTALL.

Visual Studio OpenCV CUDA build/compile

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!

4) Verify the installation

When the compilation process is finished, the binaries should be under the build\install directory.

OpenCV CUDA windows binaries

You can now follow the official OpenCV guide and integrate OpenCV with CUDA support in your own applications!

Running OpenCV with Visual C++

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.

Download OpenCV CUDA binaries

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/

 



https://blog.sciencenet.cn/blog-578676-1156239.html

上一篇:[转载]NI-DAQmx and LabVIEW Compatibility
下一篇:[转载]Why is “using namespace std” considered bad practice
收藏 IP: 35.10.57.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...
扫一扫,分享此博文

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-4-16 16:32

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部