This is an old revision of the document!
Installing OpenCV4 on Ubuntu 18 and adding it to ROS
Author: Leonardo Georgescu
Email: georgl3@unlv.nevada.edu
Date: Last Edited 01-29-2020
Keywords: Dynamixel, Gantry, Ubuntu 18, OpenCV, ROS
This tutorial shows how to install OpenCV in Ubuntu 18. The tutorial is based on this page which is in Korean Opencv Update.
Installation Guide
1. Check to see if Ubuntu is already installed:
dasl@dasl-XPS-8900:</fc>~$ pkg-config --modversion opencv
2. If you see it already installed delete the previous version by executing the following commands:
dasl@dasl-XPS-8900:~$ sudo apt-get purge libopencv* python-opencv dasl@dasl-XPS-8900:~$ sudo apt-get autoremove
3. Delete all the existing libraries:
dasl@dasl-XPS-8900:~$ sudo find /usr/local/ -name "*opencv*" -exec rm {} \;
4. Update packages on Ubuntu:
dasl@dasl-XPS-8900:~$ sudo apt-get update
5. Install build-essential packages:
dasl@dasl-XPS-8900:~$ sudo apt-get install build-essential cmake
6. Install pkg-config:
dasl@dasl-XPS-8900:~$ sudo apt-get install pkg-config
7. Install packages for recording images in a certain format:
dasl@dasl-XPS-8900:~$ sudo apt-get install libjpeg-dev libtiff5-dev libpng-dev dasl@dasl-XPS-8900:~$ sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libxvidcore-dev libx264-dev libxine2-dev
8. Install drivers to capture real-time video capture on Linux:
dasl@dasl-XPS-8900:~$ sudo apt-get install libv4l-dev v4l-utils
9. Install GStreamer:
dasl@dasl-XPS-8900:~$ sudo apt-get install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev
10. Use GUI to show images:
dasl@dasl-XPS-8900:~$ sudo apt-get install libgtk2.0-dev
11. Install OpenGL:
dasl@dasl-XPS-8900:~$ sudo apt-get install mesa-utils libgl1-mesa-dri libgtkgl2.0-dev libgtkglext1-dev
12. Install OpenCV:
dasl@dasl-XPS-8900:~$ sudo apt-get install libatlas-base-dev gfortran libeigen3-dev
13. Install Python dev packages:
dasl@dasl-XPS-8900:~$ sudo apt-get install python2.7-dev python3-dev python-numpy python3-numpy
14. Create OpenCV directory:
dasl@dasl-XPS-8900:~$ mkdir opencv dasl@dasl-XPS-8900:~$ cd opencv dasl@dasl-XPS-8900:~/opencv$
15. Download and unzip OpenCV 4.2:
dasl@dasl-XPS-8900:~/opencv$ wget -O opencv.zip https://github.com/opencv/opencv/archive/4.2.0.zip dasl@dasl-XPS-8900:~/opencv$ unzip opencv.zip
16. Download and unzip OpenCV source code:
dasl@dasl-XPS-8900:~/opencv$ wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/4.2.0.zip dasl@dasl-XPS-8900:~/opencv$ unzip opencv_contrib.zip
17. Version “opencv-4.2.0” should show when checking to see it was installed correctly:
dasl@dasl-XPS-8900:~/opencv$ ls -d */
18. Create a build directory which takes care of compilation:
dasl@dasl-XPS-8900:~/opencv$ cd opencv-4.0.1/ dasl@dasl-XPS-8900:~/opencv/opencv-4.2.0$ mkdir build dasl@dasl-XPS-8900:~/opencv/opencv-4.2.0$ cd build dasl@dasl-XPS-8900:~/opencv/opencv-4.2.0/build$
19. Produce pkg-config files in your build file. Could not upload the code here because daslhub would not accept it. To find the code go to the original page which is linked at the top and copy accordingly. If you can't find it, please email me.
dasl@dasl-XPS-8900:~/opencv/opencv-4.2.0/build$ cmake -D CMAKE_BUILD_TYPE=RELEASE....................
20. Installation should be successful. Then, check how many cores you have available on the computer:
dasl@dasl-XPS-8900:~$ lscpu
21. If you have more than 4 cores, then use the following command:
dasl@dasl-XPS-8900:~/opencv/opencv-4.2.0/build$ time make -j4
22. Install Output:
dasl@dasl-XPS-8900:~/opencv/opencv-4.2.0/build$ sudo make install
23. Check that “/usr/local/lib” is an output. If it's an output then work is all done.
dasl@dasl-XPS-8900:~/opencv/opencv-4.2.0/build$ cat /etc/ld.so.conf.d/*
24. Install CV Bridge which works between ROS and CV.
dasl@dasl-XPS-8900:~$ sudo apt-get install ros-melodic-cv-bridge
25. Here is the CMAKELIST USED:
Adding OpenCV to ROS