Installing OpenCV 3.0.0 with NVIDIA CUDA 7.5 on Ubuntu 14.04 64bit

Installing OpenCV with NVIDIA CUDA is useful if you plan to run computationally intensive image processing algorithms. These are the steps I had to follow to install OpenCV 3.0.0 with CUDA 7.5.

The latest NVIDIA driver should be installed on your PC. Do not download the driver from NVIDIA because you might run into issues such as login screen loops. Instead, install it from the Ubuntu Repositories using the following command,

sudo apt-get install nvidia-current

Now download the cuda deb[network] file from

and follow the installation instructions

  1. sudo dpkg -i cuda-repo-ubuntu1404_7.5-18_amd64.deb
  2. sudo apt-get update
  3. sudo apt-get install cuda

If you don’t run into any problems, your CUDA installation now complete. Now you can proceed to OpenCV installation.

First you need to install the dependencies,

sudo apt-get install cmake cmake-curses-gui git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev

While installing the dependencies, apt-get might refuse to install some dependencies if they are outdated. Then you just have to find the new versions and install them instead. After installing the dependencies, download OpenCV source. You may make a ‘opencv’  folder in home directory for keeping the source and building the binaries. Go to opencv git repository  and download the source to ~/opencv.

Now open a terminal. And run the following commands.

cd ~/opencv
mkdir build
cd build
ccmake .

I like to use ccmake instead of cmake since it allows me to configure the installation easily. You can select what packages you want to be installed in your PC. I have uploaded screenshots of my configuration.

With_TBB must be set to ON for PC in order to utilize all cores on your CPU for OpenCV programs. Build_TBB should be set to OFF for PC. WITH_CUDA must be set to ON to enable GPU support. The rest of the CUDA settings that are generated automatically by your configuration will be usually correct since you already installed CUDA.

Most of the time you will be compiling only for the GPU architecture of your GPU, so there is a option to select the GPU architecture ‘CUDA_ARCH_BIN’. Set the parameter equal to the compute capability of your GPU. This will greatly reduce the compilation time.

After you configure your installation, compile and install it using,

make -j $(nproc)
sudo make install

Try some OpenCV examples that use GPU acceleration. It is possible that some algorithms might run slower on GPU compared to running on the CPU. One possible reason is the time that it takes to transfer the image data, etc to the GPU. Another possible reason would be your GPU is in power saving mode. Check the powermizer settings in NVIDIA X Server Settings.


Simulation of a SCARA robot using MATLAB robotics toolbox

Lets say we want to drive the robot end-effector in constant velocity along a rounded rectangular path to mimic a glue dispensing application. The Jacobian can be used to find the angular velocities required in order to maintain the end-effector velocity constant. The referenced robot is Adapt S350 SCARA, but only 2 degrees of freedom are used. The simulation can be done in MATLAB using the robotics toolbox as follows.



%clear all;

a1= 12.5;
a2 =25.5;
theta1 = pi/4;
theta2 = pi/8;
d3 =2;

%Initial position
ini_x = -9;
ini_y = 20;
ini_z = 0;
ini_q = [0.399    2.100 0];
% Time between two points in seconds
t = 0.05;

% Number of points along the path
pts = 485;

% Time segments for plotting graphs
tGraph  = 0:0.05:t*pts;

%Defining the robot
L1 = Link([theta1 0 a1 0 0]);
L2 = Link([theta2 0 a2 pi 0]);
L3 = Link([0 d3 0 0 1]);
L = SerialLink([L1 L2 L3]); = 'SCARA';

%Initializing Matrices for linear and angular velocity storage
linearVs = zeros(pts,3);
angularVs = zeros(pts,3);
SCARADrawn_XYZp = zeros(pts,3);


%Initial Pose
T = transl(ini_x, ini_y, ini_z);
qs = L.ikine(T, [0.399    2.100 0], [1 1 1 0 0 0])
plot(L ,qs,'workspace', [-pi pi -pi pi -5 5])
qs = qs';

for i = 1:pts
%Calculating the Jacobian for the current coordinate
T = transl(contour(i,1),contour(i,2),0);
qs = L.ikine(T, qs, [1 1 1 0 0 0]);
J = jacob0(L, qs);

Jxyz = J(1:3,:);

%Calculating the required angular velocities
qd = inv(Jxyz)*  [contour(i,3) contour(i,4) 0 ]';
angularVs(i,:) = qd';

xd = Jxyz*qd;

% Angular displacement
qs =  qs' + qd*t;


% Plot the robot
plot(L ,qs','workspace', [-pi pi -pi pi -5 5])

% XY Plot
Tfkine = L.fkine(qs');
p = transl(Tfkine);
hold on;
plot(p(1), p(2))
SCARADrawn_XYZp(i,:) = p';


The contour matrix has 4 columns for position x, position y, velocity x, velocity y and the number of rows equals to the number points along the path. The time between two points is set to 0.05s. By defining the matrix contour as desired, the required angular velocities for the joints can be found.