Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Installing OpenCV 3.1 on Ubuntu 16.04 with Cuda 8 support

This is a guide for installing OpenCV 3.1 on Ubuntu 16.04 with Cuda 8 support. This has been tested using a system with a GeForce GTX 1060 and on one with a GeForce GTX 1080.

Nvidia Drivers with Compiz

Install Nvidia drivers

# Start clean
sudo apt purge nvidia-*
# Add the PPA
sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt update

For Cuda support we need the compatible driver version (generally NOT the newest). For Cuda 8 driver version 367.57 was used.

sudo apt-get install nvidia-367

UPDATE: now it seems that nvidia-367 actually installs nvidia-375 due to security reasons. See

Fixing Unity if it doesn't boot (from

sudo rm -fr ~/.cache/compizconfig-1
sudo rm -fr ~/.compiz

Then try this if your session not loading :

sudo rm -fr ~/.Xauthority
sudo rm -fr ~/.config/autostart

Reinstall compiz

sudo apt-get install --reinstall ubuntu-desktop unity compizconfig-settings-manager upstart

In addition on some systems the secure boot BIOS settings have to be modified. On the Asus x99-a II motherboard the Secure Boot option is set to "Windows Only" by default. Setting it to "Other OS" allows Ubuntu to use Nvidia drivers (see

Cuda Setup

Install CUDA 8 and CuDNN 5.1 from Nvidia's developer site: Download cuda 8.0 and run the following:

cd ~/Downloads
sudo dpkg -i cuda-repo-ubuntu1604-8-0-local_8.0.44-1_amd64.deb
sudo apt update
sudo apt install cuda

NOTE: techincally the following step is not required for OpenCV since this is the Cuda Deep Learning library, but it is included here for conveneince (it is required for libraries such as Caffe).
Get the "cuDNN v5.1 Library for Linux" from (need to register) and then run the following:

sudo tar -xvf cudnn-8.0-linux-x64-v5.1.tgz -C /usr/local

Then add the following to your ~/.bashrc

vim ~/.bashrc
export LD_LIBRARY_PATH=/usr/local/cuda/lib64
export PATH=$PATH:/usr/local/cuda-8.0/bin

OpenCV Setup

sudo apt-get install cmake cmake-qt-gui

Get OpenCV 3.1 from this fork for CUDA 8 support:

mkdir ~/code/opencv-3.1.0
cd ~/code/opencv-3.1.0
git clone .
git checkout 3.1.0-with-cuda8

See the following for more details:

Adapted from this guide: Package pre-reqs

sudo apt install --assume-yes build-essential cmake git pkg-config unzip ffmpeg qtbase5-dev python-dev python3-dev python-numpy python3-numpy
sudo apt install libhdf5-dev
sudo apt install --assume-yes libgtk-3-dev libdc1394-22 libdc1394-22-dev libjpeg-dev libpng12-dev libtiff5-dev libjasper-dev
sudo apt install --assume-yes libavcodec-dev libavformat-dev libswscale-dev libxine2-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev
sudo apt install --assume-yes libv4l-dev libtbb-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev
sudo apt install --assume-yes libvorbis-dev libxvidcore-dev v4l-utils

Configure CMake

cd ~/code/opencv-3.1.0
mkdir build
cd build

You should see the following after cmake finishes:

--   Other third-party libraries:
--     Use Cuda:                    YES (ver 8.0)
--     Use CUFFT:                   YES
--     Use CUBLAS:                  YES
--     USE NVCUVID:                 NO
--     NVIDIA GPU arch:             20 21 30 35
--     NVIDIA PTX archs:            30
--     Use fast math:               NO

Finally build OpenCV!

# Build!
make -j $(($(nproc) + 1))
sudo make install
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.