Skip to content

adutta/howtobuild_OpenCVCUDA_cpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

How to Build OpenCV with CUDA

How to build OpenCV with CUDA for C++ on Windows

Intro

Does your Windows PC have an GPU made by NVIDIA?

Good news: you can use those CUDA cores with OpenCV! Even the weakest GPUs can boost your computation time. Bad news: You can't download this. You will need to build OpenCV to work with your GPU. Worse news: There's so many options that you might be overwhelmed by what to and not to do.

This guide is intended to help you quickly figure out what you need to do to build OpenCV so it can leverage your CUDA cores. This was created with a bit of trial and error.

Prerequisites:

PC Requirements

  • 64-bit Windows OS
  • An NVIDIA GPU with CUDA cores
  • ~5GB of space free on a single drive

Software

Before you start, there's a few things that you will need to download and install for your machine:

Visual Studio Notes

  • The version of Visual Studio you need will be dependent on your compatibility requirements.
  • Make sure you download the C++ support and it can build 64-bit.
  • Make sure VS it's in your path as well.

Download OpenCV

Get the latest relase. This contains your source code.

Link: http://opencv.org/releases.html

Generate Code with CMake

CMake is a GUI tool to configure OpenCV to your liking before it's built.

  1. Point CMake to where the source code is. Look for the directory with the CMakeLists.txt file in it.
  2. Hit configure

alt text

  1. Check the following:
  • WITH_CUDA
  • WITH_CUBLAS
  • CUDA_FAST_MATH

Check only if you do not care about absolute accuracy. The tradeoff here is accuracy for speed.

  • BUILD_opencv_world

Select only if you don't plan to deploy this. This will build everything into one lib/dll. This is not lean at all.

  • INSTALL_TESTS

Lets you verify everything works.

  1. Uncheck the BUILD_opencv_python2 flag if you don't plan on using python
  • Otherwise you will need Python with debug built on your machine

alt text

  1. Hit configure again/until the red text highlights go away
  2. Finally: Hit Generate button to build C++ code

Build with Visual Studio

The code has now been configured as you need it. Now we actually get to build OpenCV.

  1. MAKE SURE BUILDING 64 BIT

alt text

  1. Build debug and release
  2. Build ALL_BUILD
  3. Build INSTALL
Go to Solution Explorer Right click the project you want to build
alt text alt text
  • Expect 2 hours to build each ALL_BUILD.
  • Change your power settings temporarily so your computer doesn't fall asleep during this.
  1. Look for [build directory]/install/ for dlls, libs, test programs for debug and release
  2. Review OpenCVConfig.cmake file to double check how things were configured

Test

Run a subset (or all if you really want to ) of the test executables with Command Prompt/PowerShell to see if things built correctly

  • Have the lena.png and lena.jpg in the exe directory. Some tests will need these. They can be found in the original OpenCV source directory.
  • At a minimum, "opencv_test_core.exe" should be tested

Move OpenCV Where You Want

Move your new opencv to the place you want (C drive maybe?)

  • What you want will be in the "../install" directory. Once you move it, rename it something like "../opencv"
  • Add "../opencv/bin" to your path (has all the dlls)

Setting Up Visual Studio Project

This part will be very similar to what OpenCV's documentation has. Link to 2.4 documentation in the reference section below. I use the local method here, but you can use the global method if you wish.

  1. Build for 64 bit only. This is a requirement to use the GPU.

alt text

  1. Include Debug and Release libs that you require
  2. Edit Project for C/C++: include additional libraries
  3. Edit Project for Linker: include opencv lib
  4. Add additional libraries under Linker
  5. Repeat for release building

If Visual Studio complains about pdb symbols not being found, you may need to grab symbols from Microsoft for debugging:

  • Tools->Options->Debugging->Symbols and select checkbox "Microsoft Symbol Servers"

Notes:

  • Firewalls/proxys may make things tricky for you! Manually downloading dlls and other items may be required.
  • Remember that to use the GPU, you must first download matricies to the GPU. Once you're finished, upload back to the CPU.

References/Thanks:

About

Guide to build OpenCV with CUDA for C++

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors