diff --git a/CONDA.md b/CONDA.md index b1f6c9b0..a4e5b293 100644 --- a/CONDA.md +++ b/CONDA.md @@ -46,11 +46,19 @@ Now, you can launch pySLAM scripts. ## Deactivate `pyslam` conda environment -To deactivate the `pyslam` environment, use +To deactivate the `pyslam` environment, run ``` $ conda deactivate ``` +## Delete `pyslam` conda environment + +To delete the `pyslam` environment, run +``` +$ . pyenv-conda-delete.sh +``` + + --- # General Notes About Conda diff --git a/PYTHON-VIRTUAL-ENVS.md b/PYTHON-VIRTUAL-ENVS.md index ddfe4a8e..136ae404 100644 --- a/PYTHON-VIRTUAL-ENVS.md +++ b/PYTHON-VIRTUAL-ENVS.md @@ -1,8 +1,32 @@ # pySLAM2 Virtual Environment +The following instructions allow you to create a custom `pyslam` virtual environment by using the package `python3-venv`. You will be able to run pyslam scripts within such environment. + +## Basic Installation + +In order to run `main_vo.py` with venv, get in the root of this repository and run the following command: +``` +$ . pyenv-create.sh +``` +**N.B.**: do not forget the dot! (without '/' !) + +This will create a custom `pyslam` environment and will also activate it. + +## Full Installation + +In order to run `main_slam.py` with venv, get in the root of this repository and run the following command: +``` +$ . install_all_venv.sh +``` +**N.B.**: do not forget the dot! (without '/' !) + +This will compile the required thirdparty packages and will also activate the created `pyslam` environment. + + + ## Create a `pyslam` python virtual environment -In order to create a custom `pyslam` python virtual environment, get in the root of this repository and run the following command: +You already see this above. In order to create a custom `pyslam` python virtual environment, get in the root of this repository and run the following command: ``` $ . pyenv-create.sh ``` @@ -25,6 +49,13 @@ Run the command: $ deactivate ``` +## Delete `pyslam` environment + +To delete the `pyslam` environment, run +``` +$ . pyenv-delete.sh +``` + --- # General Notes About Python Virtual Environments diff --git a/TROUBLESHOOTING.md b/TROUBLESHOOTING.md index 15d94017..a1e869c9 100644 --- a/TROUBLESHOOTING.md +++ b/TROUBLESHOOTING.md @@ -54,7 +54,9 @@ If you get an error message like import g2o ModuleNotFoundError: No module named 'g2o' error ``` -it's very likely you have libraries compiled in a 'mixed' way. Then, try to clean everything with the script `clean.sh`, and follow the installation procedure again. +First of all, check if you have a compiled `thirdparty/g2opy/lib/g2o.cpython-*-linux-gnu.so`. If not, Did you use one of the install_all scripts? Depending on your selected working environment (native, conda, python3-venv), you need to launch its companion install_all script in order to actually install all the required libraries (including g2o). Please, read the install instruction in the main [README](./README.md) file. + +On the other hand, if you already have a compiled `thirdparty/g2opy/lib/g2o.cpython-*-linux-gnu.so`, it's very likely you have libraries compiled in a 'mixed' way. Then, try to clean everything with the script `clean.sh`, and follow the installation procedure again (see the main [README](./README.md) file). ### Problems with ROS and OpenCV diff --git a/clean.sh b/clean.sh index 1032ff40..7d6d64ca 100755 --- a/clean.sh +++ b/clean.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -# clean thirdparty install and utils +# clean thirdparty install and compiled libraries # ==================================================== # import the utils @@ -14,7 +14,17 @@ print_blue "==================================================================" print_blue "clearning thirdparty packages and utils..." rm -Rf thirdparty/pangolin + rm -Rf thirdparty/g2opy -rm -Rf thirdparty/protoc # set by install_delf.sh + +rm -Rf thirdparty/protoc # set by install_delf.sh + rm -Rf thirdparty/orbslam2_features/build -rm -Rf cpp/utils/build \ No newline at end of file +rm -Rf thirdparty/orbslam2_features/lib + +rm -Rf cpp/utils/build +rm -Rf cpp/utils/lib + + +# TODO +# clean downloaded models \ No newline at end of file diff --git a/cpp/utils/CMakeLists.txt b/cpp/utils/CMakeLists.txt index 969903fe..d7913542 100644 --- a/cpp/utils/CMakeLists.txt +++ b/cpp/utils/CMakeLists.txt @@ -7,6 +7,8 @@ ENDIF() set(CMAKE_CXX_STANDARD 11) +set(WITH_PYTHON_INTERP_CHECK OFF CACHE BOOL "Checking python interpreter") # to be activate when called within virtual python environment + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -march=native -fPIC -DNDEBUG") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -march=native -fPIC -DNDEBUG") @@ -22,7 +24,16 @@ message(STATUS "opencv include: ${OpenCV_INCLUDE_DIRS}") message(STATUS "opencv lib dirs: ${OpenCV_INSTALL_PATH}") message(STATUS "opencv libs: ${OpenCV_LIBS}") -find_package(PythonLibs) + +# the following 2 lines are added to correctly detect the python version +if(WITH_PYTHON_INTERP_CHECK) + message(STATUS "WITH_PYTHON_INTERP_CHECK: ${WITH_PYTHON_INTERP_CHECK}") + find_package(PythonInterp) + find_package(PythonLibs) + message(STATUS "PythonInterp: ${PythonInterp}") + message(STATUS "PythonLibs: ${PythonLibs}") +endif() + include_directories( ${PYTHON_INCLUDE_DIRS} diff --git a/cpp/utils/build.sh b/cpp/utils/build.sh index bd3a813d..6632eb3f 100755 --- a/cpp/utils/build.sh +++ b/cpp/utils/build.sh @@ -6,11 +6,17 @@ if [ ! -d $1 ]; then fi } -STARTING_DIR=`pwd` +# ==================================================== +# check if we have external options +EXTERNAL_OPTION=$1 +if [[ -n "$EXTERNAL_OPTION" ]]; then + echo "external option: $EXTERNAL_OPTION" +fi +# ==================================================== make_dir build cd build -cmake .. +cmake .. $EXTERNAL_OPTION make -j 4 -cd $STARTING_DIR +cd .. diff --git a/install_all.sh b/install_all.sh index d956eb64..adfcd023 100755 --- a/install_all.sh +++ b/install_all.sh @@ -2,16 +2,16 @@ #N.B: this install script allows you to run main_slam.py and all the scripts +set -e + # ==================================================== # import the utils . bash_utils.sh # ==================================================== -set -e - -# set up git submodules -./install_basic.sh +# install basic modules and set up git submodules +. install_basic.sh # use . in order to inherit python env configuration and possible other env vars # build and install thirdparty -./install_thirdparty.sh \ No newline at end of file +. install_thirdparty.sh # use . in order to inherit python env configuration and possible other env vars \ No newline at end of file diff --git a/install_all_conda.sh b/install_all_conda.sh index c44202e6..eb584197 100755 --- a/install_all_conda.sh +++ b/install_all_conda.sh @@ -8,16 +8,22 @@ # ==================================================== -set -e +#set -e # set up git submodules -./install_basic.sh 0 # the '0' is an option for skipping pip3 packages installation +. install_basic.sh 0 0 # the first '0' is an option for skipping pip3 packages installation (script install_pip3_packages.sh), + # the second '0' is for skipping the install_cpp.sh script therein (that will be called below) # create a pyslam environment within conda and activate it . pyenv-conda-create.sh +export WITH_PYTHON_INTERP_CHECK=ON # in order to detect the correct python interpreter + +# build and install cpp stuff +. install_cpp.sh # use . in order to inherit python env configuration and other environment vars + # build and install thirdparty -. install_thirdparty.sh +. install_thirdparty.sh # use . in order to inherit python env configuration and other environment vars # N.B.: diff --git a/install_all_venv.sh b/install_all_venv.sh new file mode 100755 index 00000000..5c296c6f --- /dev/null +++ b/install_all_venv.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash + +#N.B: this install script allows you to run main_slam.py and all the scripts + +# ==================================================== +# import the utils +. bash_utils.sh + +# ==================================================== + +#set -e + +# set up git submodules +. install_basic.sh 0 0 # the first '0' is an option for skipping pip3 packages installation (script install_pip3_packages.sh), + # the second '0' is for skipping the install_cpp.sh script therein (that will be called below) + +# create a pyslam environment within venv +. pyenv-create.sh + +export WITH_PYTHON_INTERP_CHECK=ON # in order to detect the correct python interpreter + +# build and install cpp stuff +. install_cpp.sh # use . in order to inherit python env configuration and other environment vars + +# build and install thirdparty +. install_thirdparty.sh # use . in order to inherit python env configuration and other environment vars + + +# N.B.: +# if your run into troubles with opencv xfeatures2D/SIFT/SURF then run the following commands into your pyslam environment +# $ pip3 uninstall opencv-contrib-python +# $ pip3 install opencv-contrib-python==3.4.2.16 + +# HACK (this is actually run inside the created pyenv environment ) +#pip uninstall opencv-contrib-python +#pip install opencv-contrib-python==3.4.2.16 diff --git a/install_basic.sh b/install_basic.sh index 9009dafd..9680fd81 100755 --- a/install_basic.sh +++ b/install_basic.sh @@ -1,7 +1,9 @@ #!/usr/bin/env bash #N.B: this install script allows you to run main_vo.py and the test scripts -# echo "usage: ./${0##*/} " # the argument is optional +# echo "usage: ./${0##*/} " # the arguments are optional + +#set -e # ==================================================== # import the utils @@ -10,29 +12,39 @@ # ==================================================== export INSTALL_PIP3_PACKAGES=1 # install pip3 packages by default -if [ $# -eq 1 ]; then +if [ $# -ge 1 ]; then # check optional argument INSTALL_PIP3_PACKAGES=$1 echo INSTALL_PIP3_PACKAGES: $INSTALL_PIP3_PACKAGES fi -# ==================================================== -set -e +export INSTALL_CPP=1 # install cpp by default +if [ $# -ge 2 ]; then + # check optional argument + INSTALL_CPP=$2 + echo INSTALL_CPP: $INSTALL_CPP +fi + +# ==================================================== echo `pwd` # install system packages -./install_system_packages.sh +. install_system_packages.sh # use . in order to inherit python env configuration # install pip3 packages # N.B.: install_pip3_packages script can be skipped if you intend to use a virtual python environment if [ $INSTALL_PIP3_PACKAGES -eq 1 ]; then echo 'installing pip3 packages' - ./install_pip3_packages.sh + ./install_pip3_packages.sh fi # set up git submodules ./install_git_modules.sh # build and install cpp stuff -./install_cpp.sh +# N.B.: install_cpp script can be skipped here if you intend to use a virtual python environment +# but it must be then called within your virtual python environment in order to properly install libs +if [ $INSTALL_CPP -eq 1 ]; then + ./install_cpp.sh +fi diff --git a/install_cpp.sh b/install_cpp.sh index 4a850395..2bbeceeb 100755 --- a/install_cpp.sh +++ b/install_cpp.sh @@ -7,7 +7,23 @@ # ==================================================== -set -e +#set -e + + +# ==================================================== +# check if we have external options +EXTERNAL_OPTION=$1 +if [[ -n "$EXTERNAL_OPTION" ]]; then + echo "external option: $EXTERNAL_OPTION" +fi + +# check if we want to add a python interpreter check +if [[ -n "$WITH_PYTHON_INTERP_CHECK" ]]; then + echo "WITH_PYTHON_INTERP_CHECK: $WITH_PYTHON_INTERP_CHECK " + EXTERNAL_OPTION="$EXTERNAL_OPTION -DWITH_PYTHON_INTERP_CHECK=$WITH_PYTHON_INTERP_CHECK" +fi +# ==================================================== + print_blue '================================================' print_blue "Building and installing cpp ..." @@ -16,8 +32,10 @@ cd cpp # build utils cd utils -./build.sh +. build.sh $EXTERNAL_OPTION # use . in order to inherit python env configuration cd .. -# ... +cd .. + + diff --git a/install_delf.sh b/install_delf.sh index 49c57259..740be723 100755 --- a/install_delf.sh +++ b/install_delf.sh @@ -10,7 +10,7 @@ STARTING_DIR=`pwd` # this should be the main folder directory of the repo -set -e +#set -e # N.B.: this must be run after having run the script install_git_modules.sh diff --git a/install_git_modules.sh b/install_git_modules.sh index a5ac8959..f578ef0c 100755 --- a/install_git_modules.sh +++ b/install_git_modules.sh @@ -7,7 +7,7 @@ # ==================================================== -set -e +#set -e STARTING_DIR=`pwd` # this should be the main folder directory of the repo @@ -76,4 +76,5 @@ cd $STARTING_DIR # install delf -./install_delf.sh \ No newline at end of file +./install_delf.sh +cd $STARTING_DIR diff --git a/install_pip3_packages.sh b/install_pip3_packages.sh index 95ec09b5..2ad412d6 100755 --- a/install_pip3_packages.sh +++ b/install_pip3_packages.sh @@ -7,7 +7,7 @@ # ==================================================== -set -e +#set -e print_blue '================================================' print_blue "Configuring and installing python packages ..." diff --git a/install_system_packages.sh b/install_system_packages.sh index 93e3682c..a3ad3b7a 100755 --- a/install_system_packages.sh +++ b/install_system_packages.sh @@ -7,7 +7,7 @@ # ==================================================== -set -e +#set -e print_blue '================================================' print_blue "Configuring and installing system packages ..." diff --git a/install_thirdparty.sh b/install_thirdparty.sh index 8a9030c0..752a2f8c 100755 --- a/install_thirdparty.sh +++ b/install_thirdparty.sh @@ -1,5 +1,6 @@ #!/usr/bin/env bash +#set -e # ==================================================== # import the utils @@ -11,8 +12,6 @@ print_blue '================================================' print_blue "Building Thirdparty" print_blue '================================================' -set -e - STARTING_DIR=`pwd` # this should be the main folder directory of the repo # ==================================================== @@ -20,6 +19,21 @@ STARTING_DIR=`pwd` # this should be the main folder directory of the repo #./install_basic.sh # ==================================================== +# ==================================================== +# check if we have external options +EXTERNAL_OPTION=$1 +if [[ -n "$EXTERNAL_OPTION" ]]; then + echo "external option: $EXTERNAL_OPTION" +fi + +# check if we want to add a python interpreter check +if [[ -n "$WITH_PYTHON_INTERP_CHECK" ]]; then + echo "WITH_PYTHON_INTERP_CHECK: $WITH_PYTHON_INTERP_CHECK " + EXTERNAL_OPTION="$EXTERNAL_OPTION -DWITH_PYTHON_INTERP_CHECK=$WITH_PYTHON_INTERP_CHECK" +fi +# ==================================================== + + echo '================================================' print_blue "Configuring and building thirdparty/Pangolin ..." @@ -53,13 +67,15 @@ else cd pangolin PANGOLIN_UOIP_REVISION=3ac794a git checkout $PANGOLIN_UOIP_REVISION - cd .. + cd .. + # copy local changes + cp ./pangolin_changes/python_CMakeLists.txt ./pangolin/python/CMakeLists.txt fi cd pangolin if [ ! -f pangolin.cpython-*-linux-gnu.so ]; then make_dir build cd build - cmake .. -DBUILD_PANGOLIN_LIBREALSENSE=OFF # disable realsense + cmake .. -DBUILD_PANGOLIN_LIBREALSENSE=OFF $EXTERNAL_OPTION # disable realsense make -j8 cd .. #python setup.py install @@ -81,13 +97,14 @@ if [ ! -d g2opy ]; then cd .. # copy local changes cp ./g2opy_changes/types_six_dof_expmap.h ./g2opy/python/types/sba/types_six_dof_expmap.h - cp ./g2opy_changes/sparse_optimizer.h ./g2opy/python/core/sparse_optimizer.h + cp ./g2opy_changes/sparse_optimizer.h ./g2opy/python/core/sparse_optimizer.h + cp ./g2opy_changes/python_CMakeLists.txt ./g2opy/python/CMakeLists.txt fi cd g2opy -if [ ! -f thirdparty/g2o.cpython-*-linux-gnu.so ]; then +if [ ! -f lib/g2o.cpython-*-linux-gnu.so ]; then make_buid_dir cd build - cmake .. + cmake .. $EXTERNAL_OPTION make -j8 cd .. #python3 setup.py install --user @@ -97,6 +114,6 @@ cd $STARTING_DIR print_blue "==================================================================" print_blue "Configuring and building thirdparty/orbslam2_features ..." cd thirdparty/orbslam2_features -. build.sh +. build.sh $EXTERNAL_OPTION cd $STARTING_DIR diff --git a/pyenv-create.sh b/pyenv-create.sh index 85a3e6a8..f545ba4c 100755 --- a/pyenv-create.sh +++ b/pyenv-create.sh @@ -44,7 +44,7 @@ source $ENV_PATH/bin/activate pip3 install -r requirements-pip3.txt # HACK to fix opencv-contrib-python version! -pip3 uninstall opencv-contrib-python +pip3 uninstall opencv-contrib-python # better to clean it before installing the right version install_pip_package opencv-contrib-python==3.4.2.16 # N.B.: in order to activate the virtual environment run: diff --git a/pyenv-delete.sh b/pyenv-delete.sh index c93d16b3..3544d08e 100755 --- a/pyenv-delete.sh +++ b/pyenv-delete.sh @@ -8,7 +8,7 @@ if [[ -z "${ENV_NAME}" ]]; then ENV_NAME='pyslam' fi -ENVS_PATH=~/.python/venvs # path where to group virtual environments +ENVS_PATH=~/.python/venvs # path where to group virtual environments ENV_PATH=$ENVS_PATH/$ENV_NAME # path of the virtual environment we are creating if [ -d $ENV_PATH ]; then diff --git a/thirdparty/g2opy_changes/python_CMakeLists.txt b/thirdparty/g2opy_changes/python_CMakeLists.txt new file mode 100644 index 00000000..7fd81d29 --- /dev/null +++ b/thirdparty/g2opy_changes/python_CMakeLists.txt @@ -0,0 +1,44 @@ +set(WITH_PYTHON_INTERP_CHECK OFF CACHE BOOL "Checking python interpreter") # to be activate when called within virtual python environment + +include_directories(${PROJECT_SOURCE_DIR}) + +include_directories(${EIGEN3_INCLUDE_DIR}) +include_directories(${CHOLMOD_INCLUDE_DIR}) +include_directories(${CSPARSE_INCLUDE_DIR}) + +# the following 2 lines are added to correctly detect the python version +if(WITH_PYTHON_INTERP_CHECK) + message(STATUS "WITH_PYTHON_INTERP_CHECK: ${WITH_PYTHON_INTERP_CHECK}") + find_package(PythonInterp) + find_package(PythonLibs) + message(STATUS "PythonInterp: ${PythonInterp}") + message(STATUS "PythonLibs: ${PythonLibs}") +endif() + +# pybind11 (version 2.2.1) +LIST(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/EXTERNAL/pybind11/tools) +include_directories(${PROJECT_SOURCE_DIR}/EXTERNAL/pybind11/include) +include(pybind11Tools) + + +pybind11_add_module(g2o g2o.cpp) +target_link_libraries(g2o PRIVATE + core + solver_cholmod + solver_csparse + solver_eigen + solver_dense + solver_pcg + solver_slam2d_linear + solver_structure_only + types_data + types_icp + types_sba + types_sclam2d + types_sim3 + types_slam2d + types_slam2d_addons + types_slam3d + types_slam3d_addons + contrib +) diff --git a/thirdparty/orbslam2_features/CMakeLists.txt b/thirdparty/orbslam2_features/CMakeLists.txt index 6c1aa1f0..3ed35488 100644 --- a/thirdparty/orbslam2_features/CMakeLists.txt +++ b/thirdparty/orbslam2_features/CMakeLists.txt @@ -7,6 +7,8 @@ ENDIF() set(CMAKE_CXX_STANDARD 11) +set(WITH_PYTHON_INTERP_CHECK OFF CACHE BOOL "Checking python interpreter") # to be activate when called within virtual python environment + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -march=native -fPIC -DNDEBUG") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -march=native -fPIC -DNDEBUG") @@ -22,7 +24,16 @@ message(STATUS "opencv include: ${OpenCV_INCLUDE_DIRS}") message(STATUS "opencv lib dirs: ${OpenCV_INSTALL_PATH}") message(STATUS "opencv libs: ${OpenCV_LIBS}") -find_package(PythonLibs) + +# the following 2 lines are added to correctly detect the python version +if(WITH_PYTHON_INTERP_CHECK) + message(STATUS "WITH_PYTHON_INTERP_CHECK: ${WITH_PYTHON_INTERP_CHECK}") + find_package(PythonInterp) + find_package(PythonLibs) + message(STATUS "PythonInterp: ${PythonInterp}") + message(STATUS "PythonLibs: ${PythonLibs}") +endif() + include_directories( ${PYTHON_INCLUDE_DIRS} @@ -36,4 +47,4 @@ add_subdirectory(pybind11) pybind11_add_module(orbslam2_features orb_extractor.cpp ORBextractor.cpp) target_link_libraries(orbslam2_features PRIVATE ${OpenCV_LIBS} -) \ No newline at end of file +) diff --git a/thirdparty/orbslam2_features/build.sh b/thirdparty/orbslam2_features/build.sh index bd3a813d..6632eb3f 100755 --- a/thirdparty/orbslam2_features/build.sh +++ b/thirdparty/orbslam2_features/build.sh @@ -6,11 +6,17 @@ if [ ! -d $1 ]; then fi } -STARTING_DIR=`pwd` +# ==================================================== +# check if we have external options +EXTERNAL_OPTION=$1 +if [[ -n "$EXTERNAL_OPTION" ]]; then + echo "external option: $EXTERNAL_OPTION" +fi +# ==================================================== make_dir build cd build -cmake .. +cmake .. $EXTERNAL_OPTION make -j 4 -cd $STARTING_DIR +cd .. diff --git a/thirdparty/pangolin_changes/python_CMakeLists.txt b/thirdparty/pangolin_changes/python_CMakeLists.txt new file mode 100644 index 00000000..bf7668cb --- /dev/null +++ b/thirdparty/pangolin_changes/python_CMakeLists.txt @@ -0,0 +1,28 @@ +set(WITH_PYTHON_INTERP_CHECK OFF CACHE BOOL "Checking python interpreter") # to be activate when called within virtual python environment + +include_directories(${PROJECT_SOURCE_DIR}/include) + +# Find Eigen3 +find_package(Eigen3 REQUIRED) +include_directories(${EIGEN3_INCLUDE_DIR}) + +# the following 2 lines are added to correctly detect the python version +if(WITH_PYTHON_INTERP_CHECK) + message(STATUS "WITH_PYTHON_INTERP_CHECK: ${WITH_PYTHON_INTERP_CHECK}") + find_package(PythonInterp) + find_package(PythonLibs) + message(STATUS "PythonInterp: ${PythonInterp}") + message(STATUS "PythonLibs: ${PythonLibs}") +endif() + +#find_package(pybind11) + +# pybind11 (version 2.2.1) +LIST(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/external/pybind11/tools) +include_directories(${PROJECT_SOURCE_DIR}/external/pybind11/include) +include(pybind11Tools) + + +pybind11_add_module( pangolin pangolin.cpp ) +SET_TARGET_PROPERTIES(pangolin PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}) +target_link_libraries(pangolin PRIVATE ${LIBRARY_NAME})