Last active
September 20, 2018 13:19
-
-
Save rpapallas/e9154657a1a02446c86047561ab396e5 to your computer and use it in GitHub Desktop.
Use with care. An up-to-date shell script for installing OpenCV 3 with ROS Indigo based on https://github.com/taochenshh/OpenCV-3.1-with-Python-2.7-and-ROS-Indigo. Note that this script is not fully tested but once we test this on a new machine we will update it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Copyright (C) 2018 The University of Leeds, School of Computing | |
# | |
# This program is free software: you can redistribute it and/or modify | |
# it under the terms of the GNU General Public License as published by | |
# the Free Software Foundation, either version 3 of the License, or | |
# (at your option) any later version. | |
# | |
# This program is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
# GNU General Public License for more details. | |
# | |
# You should have received a copy of the GNU General Public License | |
# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
# | |
# References: | |
# Mainly this script was put together based on this tutorial: | |
# https://github.com/taochenshh/OpenCV-3.1-with-Python-2.7-and-ROS-Indigo | |
install_dependencies() { | |
# Note that some of these are conflicting with ROS, we can resolve | |
# this afterwards. | |
sudo apt-get install build-essential git cmake pkg-config | |
sudo apt-get install libjpeg8-dev libtiff4-dev libjasper-dev libpng12-dev | |
sudo apt-get install libilmbase-dev libilmbase6 libopenexr6 | |
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev | |
sudo apt-get install libv4l-dev libjpeg-dev libopenexr-dev | |
sudo apt-get install libgtk2.0-dev libeigen3-dev | |
sudo apt-get install libatlas-base-dev gfortran libtbb-dev qt5-default libvtk6-dev | |
sudo apt-get install -y libdc1394-22-dev libavcodec-dev libavformat-dev | |
sudo apt-get install libswscale-dev libtheora-dev | |
sudo apt-get install libvorbis-dev libxvidcore-dev libx264-dev | |
sudo apt-get install yasm libopencore-amrnb-dev | |
sudo apt-get install libopencore-amrwb-dev libv4l-dev libxine2-dev | |
sudo apt-get install -y doxygen | |
sudo apt-get install -y python-dev python-tk python-numpy | |
} | |
upgrade_cmake() { | |
# We need to upgrade cmake to 3.5.1+ so we can compile OpenCV3. | |
sudo -E add-apt-repository -y ppa:george-edison55/cmake-3.x | |
sudo -E apt-get update | |
sudo apt-get install cmake3 | |
} | |
compile_opencv3_from_source() { | |
mkdir -p ~/local/opencv3 | |
cd ~/local/opencv3 | |
git clone https://github.com/Itseez/opencv.git | |
cd opencv | |
git checkout 3.4.3 # Currently opencv is at version 4+ we need to checkout to 3.4.3 | |
cd ~/local/opencv3 | |
git clone https://github.com/Itseez/opencv_contrib.git | |
git checkout 3.4.3 | |
cd ~/local/opencv3/opencv | |
mkdir build | |
cd build | |
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=$HOME/local/opencv3/opencv_contrib/modules -DINSTALL_C_EXAMPLES=ON -DINSTALL_PYTHON_EXAMPLES=ON -DBUILD_EXAMPLES=ON -DWITH_IPP=ON -DBUILD_NEW_PYTHON_SUPPORT=ON -D WITH_TBB=ON -D WITH_V4L=ON -D WITH_QT=ON -D WITH_OPENGL=ON -DWITH_OPENCL=ON -DWITH_VTK=ON -DBUILD_TIFF=ON -DWITH_EIGEN=ON -DPYTHON_EXECUTABLE=$(which python) -DPYTHON_INCLUDE_DIR=$(python -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") -DPYTHON_PACKAGES_PATH=$(python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") .. | |
make -j8 | |
sudo make install | |
sudo sh -c "echo '/usr/local/lib' >> /etc/ld.so.conf.d/opencv.conf" | |
sudo ldconfig | |
sudo sh -c "echo 'PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig' >> /etc/bash.bashrc" | |
sudo sh -c "echo 'export PKG_CONFIG_PATH' >> /etc/bash.bashrc" | |
} | |
link_opencv3_with_ros_indigo() { | |
cd ~/Downloads | |
git clone https://github.com/ros-perception/vision_opencv.git | |
cd vision_opencv | |
cp -rf cv_bridge ~/catkin_ws/src | |
cd .. | |
rm -rf vision_opencv | |
cd ~/catkin_ws/src | |
mv cv_bridge cv_bridge_new | |
cd cv_bridge_new | |
sed -i '/project(cv_bridge)/c\project(cv_bridge_new)' CMakeLists.txt | |
sed '/project(cv_bridge_new)/a set (CMAKE_CXX_STANDARD 11)' CMakeLists.txt | |
sed '/(CMAKE_CXX_STANDARD 11)/a set (OpenCV_DIR $HOME/local/opencv3/opencv/build)' CMakeLists.txt | |
sed -i '/<name>cv_bridge</name>/c\<name>cv_bridge_new</name>' package.xml | |
sed -i '/<build_depend version_gte="3.3.0">opencv3</build_depend>/c\<build_depend version_gte="3.4.0">opencv3</build_depend>' package.xml | |
sed -i '/<exec_depend version_gte="3.3.0">opencv3</exec_depend>/c\<exec_depend version_gte="3.4.0">opencv3</exec_depend>' package.xml | |
cd ~/catkin_ws | |
catkin_make | |
} | |
resolve_ros_conflicts_and_reinstall_ros_indigo() { | |
sudo aptitude ros-indigo-desktop-full | |
sudo apt-get -y install ros-indigo-desktop-full | |
source ~/.bashrc | |
} | |
# Please uncomment carefully. | |
# sudo apt-get -y update | |
# sudo apt-get -y upgrade | |
# install_dependencies | |
# upgrade_cmake | |
# compile_opencv3_from_source | |
# link_opencv3_with_ros_indigo | |
# resolve_ros_conflicts_and_reinstall_ros_indigo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment