Building

Download

OpenSfM code is available at Github. The simplest way to get the code is to clone the repository and its submodules with:

git clone --recursive https://github.com/mapillary/OpenSfM

If you already have the code or you downloaded a release, make sure to update the submodules with:

cd OpenSfM
git submodule update --init --recursive

Install dependencies

OpenSfM depends on the following libraries that need to be installed before building it.

Python dependencies can be installed with:

pip install -r requirements

Installing dependencies on Ubuntu

See this Dockerfile for the commands to install all dependencies on Ubuntu 20.04.

Installing dependencies on Fedora

Tested on Fedora 33 & 34

sudo dnf install zlib-devel libjpeg-devel python3-devel g++ ceres-solver-devel opencv-devel python3-opencv eigen3-devel libomp cmake glog-devel

There’s an issue with the gflags-config.cmake distributed with Fedora. This quick workaround works:

sudo sed -i "s^set (GFLAGS_INCLUDE_DIR.*^set (GFLAGS_INCLUDE_DIR "/usr/include")^" /usr/lib64/cmake/gflags/gflags-config.cmake

Install python dependencies before building:

cd ~/src/OpenSfM && pip install -r requirements.txt

Installing dependencies on MacOSX

Install OpenCV and the Ceres solver using:

brew install opencv
brew install ceres-solver
brew install libomp
sudo pip install -r requirements.txt

Make sure you update your PYTHONPATH to include /usr/local/lib/python3.7/site-packages where OpenCV have been installed. For example with:

export PYTHONPATH=/usr/local/lib/python3.7/site-packages:$PYTHONPATH

Also, in order for Cmake to recognize the libraries installed by Brew, make sure that C_INCLUDE_PATH, CPLUS_INCLUDE_PATH, DYLD_LIBRARY_PATH environment variables are set correctly. For example, you can run:

export C_INCLUDE_PATH=/usr/local/include
export CPLUS_INCLUDE_PATH=/usr/local/include
export DYLD_LIBRARY_PATH=$HOME/local/lib64

Note

Note on OpenCV 3 When running OpenSfM on top of OpenCV version 3.0 the OpenCV Contrib modules are required for extracting SIFT or SURF features.

Installing dependencies on Windows

Install vcpkg from the OpenSfM root directory:

cd OpenSfM
git clone https://github.com/microsoft/vcpkg
cd vcpkg
bootstrap-vcpkg.bat

Then install OpenCV, Ceres, SuiteSparse and LAPACK (this will take a while):

vcpkg install opencv4 ceres ceres[suitesparse] lapack suitesparse --triplet x64-windows

Finally install the PIP requirements:

pip install -r requirements.txt

Building the library

Once the dependencies have been installed, you can build OpenSfM by running the following command from the main folder:

python3 setup.py build

Building the documentation

To build the documentation and browse it locally use:

python3 setup.py build_doc
python3 -m http.server --directory build/doc/html/

and browse http://localhost:8000/