Skip to content

Latest commit

 

History

History
107 lines (78 loc) · 3.33 KB

README.md

File metadata and controls

107 lines (78 loc) · 3.33 KB

Python Bundle Adjustment

These instructions are based on and almost identical to the ones at https://github.com/drormoran/gasfm/tree/main/bundle_adjustment/README.md.

Conda envorinment

Use the gasfm environment.

conda activate gasfm
export PYBIND11_PYTHON_VERSION="3.9"
export PYTHON_VERSION="3.9"

Directory structure

After this set up, the directory structure be:

gasfm
├── bundle_adjustment
│   ├── ceres-solver
│   │   ├── ceres-bin
│   │   |   └── lib
│   │   |       └── PyCeres.cpython-39-x86_64-linux-gnu.so
│   │   ├── ceres_python_bindings
│   │   |   └── python_bindings
│   │   |       └── custom_cpp_cost_functions.cpp
│   │   └── CMakeLists.txt
│   └── custom_cpp_cost_functions.cpp
├── code
├── datasets

Set up

  1. Clone the Ceres-Solver repository to the bundle_adjustment folder and check out version 2.1.0:
cd bundle_adjustment
git clone https://ceres-solver.googlesource.com/ceres-solver -b 2.1.0
  1. Clone the ceres_python_bindings package inside the ceres-solver folder:
cd ceres-solver
git clone https://github.com/Edwinem/ceres_python_bindings
  1. Copy the file "custom_cpp_cost_functions.cpp" and replace the file "ceres-solver/ceres_python_bindings/python_bindings/custom_cpp_cost_functions.cpp". This file contains projective and euclidean custom bundle adjustment functions.
cp ../custom_cpp_cost_functions.cpp ceres_python_bindings/python_bindings/custom_cpp_cost_functions.cpp

Next, you need to build ceres_python_bindings and ceres-solver and create a shared object file that python can call. You can either continue with the instructions here or follow the instructions at the ceres_python_bindings repository.

  1. run:
cd ceres_python_bindings
git submodule init
git submodule update
  1. Make sure that the C++ standard library version used during the build is recent enough, and not hard-coded to C++11 by pybind11:
sed -i 's/set(PYBIND11_CPP_STANDARD -std=c++11)/set(PYBIND11_CPP_STANDARD -std=c++17)/g' AddToCeres.cmake
  1. Add to the end of the file ceres-solver/CMakeLists.txt the line: "include(ceres_python_bindings/AddToCeres.cmake)":
cd ..
echo "include(ceres_python_bindings/AddToCeres.cmake)" >> CMakeLists.txt
  1. Inside ceres-solver folder run:
mkdir ceres-bin
cd ceres-bin
cmake ..
make -j8
make test
  1. If everything worked you should see the following file:
bundle_adjustment/ceres-solver/ceres-bin/lib/PyCeres.cpython-39-x86_64-linux-gnu.so
  1. If you want to use this bundle adjustment implementation for a different project make sure to add the path of the shared object to linux PATH (in the code this is done for you). In the python project this would be for example:
import sys
sys.path.append('../bundle_adjustment/ceres-solver/ceres-bin/lib/')
import PyCeres

To see the usage of the PyCeres functions go to code/utils/ceres_utils and code/utils/ba_functions.