Setting up CUDA – ROS – OpenCV – PCL – Gazebo and other essential libraries related to Image Processing and Robotics

This tutorial guides one in installation of CUDA, OpenCV, ROS, PCL, Realsense Packages

Installation

Install Ubuntu [ swap = 2xRAM, assign rest to \ (root) ]
[ in case of Dual boot along side windows, don’t forget to turn of secure boot and fast boot]
 
To keep the system organised, make a folder ‘workspace’ for ROS workspaces other than default, (let the default catkin_ws be at /home/user only ) and a folder packages (to keep all your build packages in one place).
 
CUDA (for Ubuntu 16.04, I prefer ver 9.0 and for 18.04 I prefer 10.1)  [ 10.2 does not support pytorch at the time this blog is written] 
 
ROS (bare-bones) ( Kinetic for 16.04, Melodic for 18.04… always go with bare bones to avoid conflicts with default packages that comes along other version)
 
CMAKE (latest) [ as upgrading to a new version might remove ros while trying to remove previous version of cmake, so it is advisable to install cmake just after installing ros…so if any thing goes wrong you can install ros again… ]
https://cmake.org/install/ [at the time, cmake 3.15 is stable release]
 
OpenCV (always build from source)
 
PCL (build from source) [ optional ]
 
Real-sense Packages [ optional ]
 

Ubuntu 16.04

Install CUDA

Step 1: Update and Upgrade your system:
sudo apt-get update 
sudo apt-get upgrade

Step 2: Verify You Have a CUDA-Capable GPU:
lspci | grep -i nvidia
Note GPU model. eg. GeForce 840M
If you do not see any settings, update the PCI hardware database that Linux maintains by entering update-pciids (generally found in /sbin) at the command line and rerun the previous lspci command.
If your graphics card is from NVIDIA then goto http://developer.nvidia.com/cuda-gpus and verify if listed in CUDA enabled gpu list.
Note down its Compute Capability. eg. GeForce 840M 5.0

Step 3: Verify You Have a Supported Version of Linux:
To determine which distribution and release number you’re running, type the following at the command line:
uname -m && cat /etc/*release
The x86_64 line indicates you are running on a 64-bit system which is supported by cuda 9.1

Step 4: Install Dependencies:
Required to compile from source:
sudo apt-get install build-essential 
sudo apt-get install cmake git unzip zip
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt-get install python2.7-dev python3.5-dev python3.6-dev pylint

Step 5: Install linux kernel header:
Goto terminal and type:
uname -r
You can get like “4.10.0-42-generic”. Note down linux kernel version.
To install linux header supported by your linux kernel do following:
sudo apt-get install linux-headers-$(uname -r)

Step 6: Install NVIDIA CUDA 9.2:

Remove previous cuda installation:
sudo apt-get purge nvidia*
sudo apt-get autoremove
sudo apt-get autoclean
sudo rm -rf /usr/local/cuda*

Install cuda :
For Ubuntu 16.04 :
sudo apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/7fa2af80.pub
echo "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64 /" | sudo tee /etc/apt/sources.list.d/cuda.list
For Ubuntu 17.10 and Ubuntu 18.04 :
sudo apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1710/x86_64/7fa2af80.pub
echo "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1710/x86_64 /" | sudo tee /etc/apt/sources.list.d/cuda.list
For Both Options:
sudo apt-get update 
sudo apt-get -o Dpkg::Options::="--force-overwrite" install cuda-9-0 cuda-drivers
Step 7: Reboot the system to load the NVIDIA drivers.
Step 8: Go to terminal and type:
echo 'export PATH=/usr/local/cuda-9.0/bin${PATH:+:${PATH}}' >> ~/.bashrc
echo 'export LD_LIBRARY_PATH=/usr/local/cuda-9.2/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}' >> ~/.bashrc
source ~/.bashrc
sudo ldconfig
nvidia-smi
 

 
Install ROS – BARE BONE

Installation

ROS Kinetic ONLY supports Wily (Ubuntu 15.10), Xenial (Ubuntu 16.04) and Jessie (Debian 8) for debian packages.
 
Configure your Ubuntu repositories
Configure your Ubuntu repositories to allow “restricted,” “universe,” and “multiverse.” You can follow the Ubuntu guide for instructions on doing this.
 
Setup your sources.list
Setup your computer to accept software from packages.ros.org.
sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
 
Set up your keys
sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
 
If you experience issues connecting to the keyserver, you can try substituting hkp://pgp.mit.edu:80 or hkp://keyserver.ubuntu.com:80 in the previous command.
Alternatively, you can use curl instead of the apt-key command, which can be helpful if you are behind a proxy server:
 
curl -sSL 'http://keyserver.ubuntu.com/pks/lookup?op=get&search=0xC1CF6E31E6BADE8868B172B4F42ED6FBAB17C654' | sudo apt-key add -
 
Installation
First, make sure your Debian package index is up-to-date:
sudo apt-get update
There are many different libraries and tools in ROS. We provided four default configurations to get you started. You can also install ROS packages individually.
In case of problems with the next step, you can use following repositories instead of the ones mentioned above ros-shadow-fixed
  • ROS-Base: (Bare Bones) ROS package, build, and communication libraries. No GUI tools.
sudo apt-get install ros-kinetic-ros-base
 
Initialize rosdep
Before you can use ROS, you will need to initialize rosdep. rosdep enables you to easily install system dependencies for source you want to compile and is required to run some core components in ROS.
sudo rosdep init
rosdep update
 
Environment setup
It’s convenient if the ROS environment variables are automatically added to your bash session every time a new shell is launched:
echo "source /opt/ros/kinetic/setup.bash" >> ~/.bashrc
source ~/.bashrc
If you have more than one ROS distribution installed, ~/.bashrc must only source the setup.bash for the version you are currently using.
If you just want to change the environment of your current shell, instead of the above you can type:
source /opt/ros/kinetic/setup.bash
If you use zsh instead of bash you need to run the following commands to set up your shell:
echo "source /opt/ros/kinetic/setup.zsh" >> ~/.zshrc
source ~/.zshrc
 
Dependencies for building packages
Up to now you have installed what you need to run the core ROS packages. To create and manage your own ROS workspaces, there are various tools and requirements that are distributed separately. For example, rosinstall is a frequently used command-line tool that enables you to easily download many source trees for ROS packages with one command.
To install this tool and other dependencies for building ROS packages, run:
sudo apt install python-rosinstall python-rosinstall-generator python-wstool build-essential
 


 
Install latest stable release of CMAKE
 


 
Install OpenCV from Source
 
To install the latest OpenCV version from the source, follow these steps:
  1. Installing the necessary packages
  • The following commands will install all required and optional dependencies:
sudo apt install build-essential cmake git pkg-config libgtk-3-dev
sudo apt install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev libxvidcore-dev libx264-dev
sudo apt install libjpeg-dev libpng-dev libtiff-dev gfortran openexr libatlas-base-dev
sudo apt install python3-dev python3-numpy libtbb2 libtbb-dev libdc1394-22-dev
 
  1. Cloning the OpenCV source code
  • Create a directory which will hold the repositories and clone the OpenCV’s and OpenCV contrib repositories with the following commands:
mkdir ~/opencv_build && cd ~/opencv_build
git clone https://github.com/opencv/opencv.git
git clone https://github.com/opencv/opencv_contrib.git
  • At the time of writing, the default version in the github repositories is version 4.0.0. If you want to install an older version of OpenCV, cd to both opencv and opencv_contrib directories and run git checkout <opencv-version>
  1. Configuring OpenCV with CMake
  • Once the download is completed create a temporary build directory, and switch to it:
cd ~/opencv_build/opencv
mkdir build && cd build
  • Set up the OpenCV build with CMake:
cmake -D CMAKE_BUILD_TYPE=RELEASE \
    -D CMAKE_INSTALL_PREFIX=/usr/local \
    -D INSTALL_C_EXAMPLES=ON \
    -D INSTALL_PYTHON_EXAMPLES=ON \
    -D OPENCV_GENERATE_PKGCONFIG=ON \
    -D OPENCV_EXTRA_MODULES_PATH=~/opencv_build/opencv_contrib/modules \
    -D BUILD_EXAMPLES=ON ..
 
  1. Compiling OpenCV
  • Modify the -j flag according to your processor. If you do not know the number of cores your processor you can find it by typing nproc. My system has 8 cores, so I am using the -j8 flag.
  • Start the compilation process:
make -j8
  1. Installing OpenCV
  • Once the compile process is completed install OpenCV with:
sudo make install


Install PCL
  • Install Dependencies :
  • eigen3
sudo apt-get update
sudo apt-get install libeigen3-dev
  • flann
sudo apt-get install libflann-dev
  • boost
  • vtk
For systems for which we do not offer precompiled binaries, you need to compile Point Cloud Library (PCL) from source. Here are the steps that you need to take: Go to Github and download the version number of your choice. Uncompress the tar-bzip archive, e.g. (replace 1.7.2 with the correct version number): [download 1.9.1]
[ download and make this package inside your “package” folder ]
 
tar xvfj pcl-pcl-1.9.1.tar.gz
Change the directory to the pcl-pcl-1.7.2 (replace 1.7.2 with the correct version number) directory, and create a build directory in there:
cd pcl-pcl-1.9.1 && mkdir build && cd build
Run the CMake build system using the default options:
cmake ..
Or change them (uses cmake-curses-gui):
ccmake ..
Please note that cmake might default to a debug build. If you want to compile a release build of PCL with enhanced compiler optimizations, you can change the build target to “Release” with “-DCMAKE_BUILD_TYPE=Release”:
cmake -DCMAKE_BUILD_TYPE=Release ..
Finally compile everything (see compiler_optimizations):
make -j4
And install the result:
make -j4 install
Or alternatively, if you did not change the variable which declares where PCL should be installed, do:
sudo make -j4 install
Here’s everything again, in case you want to copy & paste it:
cd pcl-pcl-1.7.2 && mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
make -j4
sudo make -j4 install
Again, for a detailed tutorial on how to compile and install PCL and its dependencies in Microsoft Windows, please visit our tutorials page. Additional information for developers is available at the Github PCL Wiki.
If you are eager to try out a certain feature of PCL that is currently under development (or you plan on developing and contributing to PCL), we recommend you try checking out our source repository, as shown below. If you’re just interested in browsing our source code, you can do so by visiting https://github.com/PointCloudLibrary/pcl.
Clone the repository:
git clone https://github.com/PointCloudLibrary/pcl pcl-trunk
Please note that above steps (3-5) are almost identical for compiling the experimental PCL trunk code:
cd pcl-trunk && mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo ..
make -j2
sudo make -j2 install
 
 


 
Install Realsense Packages : 
Install Realsense-ros
before_install:
 
echo 'deb http://realsense-hw-public.s3.amazonaws.com/Debian/apt-repo xenial main' || sudo tee /etc/apt/sources.list.d/realsense-public.list
  # - sudo apt-key adv --keyserver keys.gnupg.net --recv-key C8B3A55A6F3EFCDE || sudo apt-key adv --keyserver hkp://keys.gnupg.net:80 --recv-key C8B3A55A6F3EFCDE
 
sudo add-apt-repository "deb http://realsense-hw-public.s3.amazonaws.com/Debian/apt-repo xenial main"
 
sudo apt-get update -qq
 
sudo apt-get install librealsense2-dkms --allow-unauthenticated -y
 
sudo apt-get install librealsense2-dev --allow-unauthenticated -y  
 
Essential Image processing Dependencies : 
 
sudo apt-get install git libssl-dev libusb-1.0-0-dev pkg-config libgtk-3-dev
Distribution-specific packages:
Ubuntu 14 or when running of Ubuntu 16.04 live-disk:
sudo apt-get install`
./scripts/install_glfw3.sh
Ubuntu 16:
sudo apt-get install libglfw3-dev
Ubuntu 18:
sudo apt-get install libglfw3-dev libgl1-mesa-dev libglu1-mesa-dev
 
Install missing essential cv packages : 
sudo apt-get install ros-kinetic-cv-bridge -y
sudo apt-get install ros-kinetic-image-transport
sudo apt-get install ros-kinetic-tf -y
sudo apt-get install ros-kinetic-diagnostic-updater -y
sudo apt-get install ros-kinetic-ddynamic-reconfigure -y
 
 


Leave a Comment

Your email address will not be published. Required fields are marked *