Skip to content

Build on Linux [Ubuntu 16.04]

Jim edited this page May 14, 2018 · 2 revisions

Software Overview

Compiled Software

Prebuilt versions available for Windows/MacOS

  • OpenCV 3 for video frame extraction & image processing
  • CUDA for GPU optimization
  • COLMAP for photogrammetry - sparse & dense reconstruction

Python Libraries

Scripts are written for Python 2.7

Additional Software

  • Garmin VIRB Edit for extracting FIT data for video & stitching 360° videos [Windows/MacOS only]

Building on Linux (Ubuntu 16.04)

Adapted from https://www.pyimagesearch.com/2016/10/24/ubuntu-16-04-how-to-install-opencv/ and https://colmap.github.io/install.html

INSTALL DEPENDENCIES

  1. Update existing packages & Libraries
$ sudo apt-get update
$ sudo apt-get upgrade
  1. Install developer tools
$ sudo apt-get install \
    build-essential \
    cmake \
    pkg-config
  1. Install OpenCV image dependencies
$ sudo apt-get install \
    libjpeg8-dev \
    libtiff5-dev \
    libjasper-dev \
    libpng12-dev
  1. Install OpenCV video dependencies
$ sudo apt-get install \
    libavcodec-dev \
    libavformat-dev \
    libswscale-dev \
    libv4l-dev \
    libxvidcore-dev \
    libx264-dev
  1. Install OpenCV GUI dependencies
$ sudo apt-get install libgtk-3-dev
  1. Install OpenCV Optimization dependencies
$ sudo apt-get install \
    libatlas-base-dev \
    gfortran
  1. Install Python Development Libraries
$ sudo apt-get install \
    python2.7-dev \
    python3.5-dev
  1. Install COLMAP Dependencies
$ sudo apt-get install \
    libboost-all-dev \
    libeigen3-dev \
    libsuitesparse-dev \
    libfreeimage-dev \
    libgoogle-glog-dev \
    libgflags-dev \
    libglew-dev \
    qtbase5-dev \
    libqt5opengl5-dev
  1. Install latest NVIDIA drivers This must be done from the command-line environments -- installing with the GUI active will generally cause errors. Enable CLI with ctrl+alt+f2 -- you will need to login with username + password ... Delete old drivers
$ sudo apt-get purge nvidia*

Install latest drivers

$ sudo add-apt-repository ppa:graphics-drivers/ppa
$ sudo apt update
$ sudo apt install nvidia-390

Verify driver installation

$ lsmod | grep nvidia

Reboot to GUI

$ sudo reboot

INSTALL CUDA

http://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html

  1. Verify CUDA-Capable GPU
$ lspci | grep -i NVIDIA
  1. Verify gcc is installed
$ gcc --version
  1. Install kernel headers & dev packages
$ sudo apt-get install linux-headers-$(uname -r)
  1. Download CUDA 9.1 Runfile Select "runfile (local)" option > Base Installer
  2. Install CUDA You can skip installing the NVIDA driver, as we have already updated to the latest version. Follow the text prompts & change path names accordingly.
$ cd ~/Downloads
$ sudo sh cuda_<version>_linux.run

INSTALL PYTHON LIBRARIES

Make sure virtualenv is activated with workon sg2018

  1. Install with pip
$ pip install piexif fitparse

INSTALL OPENCV

  1. Download & unzip OpenCV3 & OpenCV3 Contrib (contains proprietary librarys like SIFT/SURF) Replace 3.4.1 with most current version
$ cd ~
$ wget -O opencv.zip https://github.com/Itseez/opencv/archive/3.4.1.zip
$ unzip opencv.zip
$ wget -O opencv_contrib.zip https://github.com/Itseez/opencv_contrib/archive/3.4.1.zip
$ unzip opencv_contrib.zip
  1. Install pip
$ cd ~
$ wget https://bootstrap.pypa.io/get-pip.py
$ sudo python get-pip.py
$ sudo rm -rf ~/get-pip.py ~/.cache/pip

If pip is already installed, make sure it is up-to-date

python -m pip install --upgrade pip
  1. Install & Setup Virtual Environment Optional, but recommended
$ sudo pip install virtualenv virtualenvwrapper

Update ~/.bashrc to include virtualenv commands

$ echo -e "\n# virtualenv and virtualenvwrapper" >> ~/.bashrc
$ echo "export WORKON_HOME=$HOME/.virtualenvs" >> ~/.bashrc
$ echo "source /usr/local/bin/virtualenvwrapper.sh" >> ~/.bashrc
$ source ~/.bashrc
  1. Generate Python virtual environment Here we are creating an environment named sg2018, but feel free to choose another name (and update code accordingly)
$ mkvirtualenv sg2018 -p python2

To enable the virtual environment (important for installing & building libraries) - you will see (sg2018) before the command prompt if activated.

$ workon sg2018

To de-activate the virtual environment:

$ deactivate
  1. Install NumPy (make sure virtualenv is activated)
$ pip install numpy
  1. Install OpenCV (make sure virtualenv is activated)
$ cd ~/opencv-3.4.1
$ mkdir build && cd build
$ cmake \
    -D CMAKE_BUILD_TYPE=RELEASE \
    -D CMAKE_INSTALL_PREFIX=/usr/local \
    -D INSTALL_PYTHON_EXAMPLES=ON \
    -D INSTALL_C_EXAMPLES=OFF \
    -D OPENCV_EXTRA_MODULES_PATH = ~/opencv_contrib-3.4.1/modules \
    -D PYTHON_EXECUTABLE=~/.virtualenvs/sg2018/bin/python \
    -D BUILD_EXAMPLES=ON ..

Review output to ensure paths are provided for Python (2 or 3) "Interpreter", "Libraries", "numpy", and "packages path"

  1. Compile OpenCV (use -j flag to compile with more than one processor, eg. $ make -j4 will build with 4 processors)
$ make
$ sudo make install
$ sudo ldconfig
  1. Ensure OpenCV libraries are exposed to Python 2
$ cd ~/.virtualenvs/sg2018/lib/python2.7/site-packages
$ ln -s /usr/local/lib/python2.7/site-packages/cv2.so cv2.so
  1. Test OpenCV installation & Clean-up Open Python
$ cd ~
$ workon sg2018
$ python

Import OpenCV and check version

import cv2
cv2.__version__

Delete installation ZIP directories

$ cd ~
$ rm -rf opencv-3.4.1 opencv_contrib-3.4.1 opencv.zip opencv_contrib.zip

INSTALL COLMAP

https://colmap.github.io/install.html We will build the applications in the directory ~/DEV, so adjust code if building elsewhere. NOTE: Some functionality will not be available if CUDA is not installed prior to building COLMAP.

  1. Install Ceres Solver http://ceres-solver.org/
$ cd ~/DEV
$ sudo apt-get install \
    libatlas-base-dev \
    libsuitesparse-dev
$ git clone https://ceres-solver.googlesource.com/ceres-solver
$ cd ceres-solver
$ mkdir build
$ cd build
$ cmake .. -DBUILD_TESTING=OFF -DBUILD_EXAMPLES=OFF
$ make
$ sudo make install
  1. Build COLMAP
$ cd ~/DEV
$ git clone https://github.com/colmap/colmap
$ cd colmap
$ mkdir build && cd build
$ cmake ..
$ make
$ sudo make install
  1. Run COLMAP If you run into issues/errors, close terminal and open a new window. Restarting may also be necessary.

Headless CLI mode

$ colmap -h

GUI Mode

$ colmap gui