OpenCV 3.3 was released on 03/08/2017, for instructions on building that on Windows with CUDA 8.0 and Intel MKL+TBB go here.
Because the pre-built Windows libraries available for OpenCV v3.2 do not include the CUDA modules, I have provided them for download here, and included the build instructions below for anyone who is interested.
The guide below details instructions on compiling the 64 bit version of OpenCV v3.2 shared libraries with Visual Studio 2013 (will also work with Visual Studio 2015 if selected in CMake), CUDA 8.0, and support for both the Intel Math Kernel Libraries (MKL) and Intel Threaded Building Blocks (TBB). The guide is split into two parts, the first to follow if you just want to compile OpenCV v3.2 with CUDA support and the second if you want to include the Intel performance libraries, SIMD optimizations and Eigen integration.
Note: The procedure outlined will not work for Visual Studio 2017 because this is not supported by the CUDA 8.0 Toolkit.
For Visual Studio 2013 and 2015 you first need to:
- Download the source files, available on GitHub. Either clone the git repo making sure to checkout the 3.2.0 tag or download this archive containing all the source file.
- Install CMake – Version 3.7.1 is used in the guide.
- Install The CUDA 8.0 Toolkit.
- Optional – Install both the Intel MKL and TBB by registering for community licensing, and downloading for free.
- Optional – Download and extract the Eigen C++ template library for linear algebra.
Building OpenCV v3.2 with CUDA 8.0
- Fire up CMake, making sure that the Grouped checkbox is ticked, select the location of the source files downloaded from GitHub and the location where the build will take place.
- Click the Configure button and select Visual Studio 2013 Win64 (32 bit CUDA support is limited). This may take a while as CMake will download ffmpeg and the Intel Integrated Performance Primitives for Image processing and Computer Vision (IPP-ICV).
- Expand the BUILD group, untick BUILD_DOCS (requires additional dependencies, and can be downloaded from here) and tick BUILD_opencv_world (builds to a single dll). Your only unticked build options should be the ones shown in the image below.
- Expand the CUDA tab, the CUDA_TOOLKIT_ROOT_DIR should point to your CUDA 8.0 toolkit installation, if you have more than one version of the toolkit installed and it has picked that one then simply change the path to point to CUDA 8.0.
The default CUDA_ARCH_BIN option is to build microcode for all architectures from 2.0-6.1 (Fermi–Pascal). This setting results in a large build time (~3.5hours on an i7) but the binaries produced will run on all supported devices. If you only want to execute OpenCV on a specific device then only enter the compute capability of that device here, remember that this the produced libraries are not guaranteed to run on any device’s of a different major compute version to the ones entered, see the CUDA C Programming Guide for details.
If you are comfortable with the implications, you can also enable CUDA_FAST_MATH which will enable the –use_fast_math compiler option, again see CUDA C Programming Guide for details.
- Expand WITH and enable WITH_CUBLAS to enable the CUDA Basic Linear Algebra Subroutines (cuBLAS).
- If you want to include the Intel performance libraries, SIMD optimizations and Eigen integration, go to Including Intel MKL, TBB and other optional components, before proceeding.
- Press Configure again, ensure that there are no warning messages in red in the configuration window. If there are then the Visual Studio solution may be generated but it it will probably fail to build.
- Press Generate and wait until the bottom of the window indicates success.
- Press Open Project (not available in older versions of CMake, for those just locate and open the Visual Studio solution file) to open up the solution in Visual Studio.
- Click Solution Explorer, expand CMakeTargets, right click on INSTALL and click Build. This will both build the library and copy the necessary redistributable parts to the install directory, D:/OpenCV/build/install in this example. If everything was successful, congratulations, you now have OpenCV v3.2 built with CUDA 8.0.
- NOTE: If you change remove any options after pressing Configure a second time, the build may fail, it is best to remove build directory and start again. This may seem over cautions but it is preferable to waiting for an hour for the build to fail and then starting again.
Including Intel MKL, TBB and other optional components
- If MKL and TBB are installed correctly the path to these should have been picked up in CMake (see below), all that is required is to enable TBB by ticking MKL_WITH_TBB.
and enable MKL by ticking HAVE_MKL.
- To build with SIMD optimizations enable the options shown below.
- To build with Eigen set EIGEN_INCLUDE_PATH to the directory you extracted the archive to.
- Press Configure and verify that the optional components have been selected, then proceed as above.