Skip to content

Commit

Permalink
More fixes and improvements under linux.
Browse files Browse the repository at this point in the history
  • Loading branch information
luigifreda committed Dec 5, 2024
1 parent f2f335c commit 5e799cd
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 42 deletions.
68 changes: 37 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,44 @@ Author: **[Luigi Freda](https://www.luigifreda.com)**
<!-- TOC -->

- [pySLAM v2.2.5](#pyslam-v225)
- [1. Install](#1-install)
- [1.1. Requirements](#11-requirements)
- [1.2. Ubuntu](#12-ubuntu)
- [1.3. MacOS](#13-macos)
- [1.4. Docker](#14-docker)
- [1.5. How to install non-free OpenCV modules](#15-how-to-install-non-free-opencv-modules)
- [1.6. Troubleshooting and performance issues](#16-troubleshooting-and-performance-issues)
- [2. Usage](#2-usage)
- [2.1. Feature tracking](#21-feature-tracking)
- [2.2. Loop closing](#22-loop-closing)
- [2.3. Save and reload a map](#23-save-and-reload-a-map)
- [2.4. Relocalization in a loaded map](#24-relocalization-in-a-loaded-map)
- [2.5. Trajectory saving](#25-trajectory-saving)
- [2.6. SLAM GUI](#26-slam-gui)
- [2.7. Monitor the logs for tracking, local mapping, and loop closing simultaneously](#27-monitor-the-logs-for-tracking-local-mapping-and-loop-closing-simultaneously)
- [3. Supported local features](#3-supported-local-features)
- [4. Supported matchers](#4-supported-matchers)
- [5. Supported global descriptors and local descriptor aggregation methods](#5-supported-global-descriptors-and-local-descriptor-aggregation-methods)
- [5.1. Local descriptor aggregation methods](#51-local-descriptor-aggregation-methods)
- [5.2. Global descriptors](#52-global-descriptors)
- [6. Datasets](#6-datasets)
- [6.1. KITTI Datasets](#61-kitti-datasets)
- [6.2. TUM Datasets](#62-tum-datasets)
- [6.3. EuRoC Dataset](#63-euroc-dataset)
- [7. Camera Settings](#7-camera-settings)
- [8. Comparison pySLAM vs ORB-SLAM3](#8-comparison-pyslam-vs-orb-slam3)
- [9. Contributing to pySLAM](#9-contributing-to-pyslam)
- [10. References](#10-references)
- [11. Credits](#11-credits)
- [12. TODOs](#12-todos)
- [Install](#install)
- [Requirements](#requirements)
- [Ubuntu](#ubuntu)
- [MacOS](#macos)
- [Docker](#docker)
- [How to install non-free OpenCV modules](#how-to-install-non-free-opencv-modules)
- [Troubleshooting and performance issues](#troubleshooting-and-performance-issues)
- [Usage](#usage)
- [Feature tracking](#feature-tracking)
- [Loop closing](#loop-closing)
- [Dense reconstruction pipeline](#dense-reconstruction-pipeline)
- [Save and reload a map](#save-and-reload-a-map)
- [Relocalization in a loaded map](#relocalization-in-a-loaded-map)
- [Trajectory saving](#trajectory-saving)
- [SLAM GUI](#slam-gui)
- [Monitor the logs for tracking, local mapping, and loop closing simultaneously](#monitor-the-logs-for-tracking-local-mapping-and-loop-closing-simultaneously)
- [Supported local features](#supported-local-features)
- [Supported matchers](#supported-matchers)
- [Supported global descriptors and local descriptor aggregation methods](#supported-global-descriptors-and-local-descriptor-aggregation-methods)
- [Local descriptor aggregation methods](#local-descriptor-aggregation-methods)
- [Global descriptors](#global-descriptors)
- [Datasets](#datasets)
- [KITTI Datasets](#kitti-datasets)
- [TUM Datasets](#tum-datasets)
- [EuRoC Dataset](#euroc-dataset)
- [Camera Settings](#camera-settings)
- [Comparison pySLAM vs ORB-SLAM3](#comparison-pyslam-vs-orb-slam3)
- [Contributing to pySLAM](#contributing-to-pyslam)
- [References](#references)
- [Credits](#credits)
- [TODOs](#todos)

<!-- /TOC -->

**pySLAM** is a python implementation of a *Visual SLAM* pipeline for **monocular**, **stereo** and **RGBD** cameras.
- It supports many classical and modern **[local features](#supported-local-features)** and it offers a convenient interface for them.
- It implements loop closing via **[descriptor aggregators](#supported-global-descriptors-and-local-descriptor-aggregation-methods)** such as visual Bag of Words (BoW, iBow), Vector of Locally Aggregated Descriptors (VLAD) and other modern **[global descriptors](#supported-global-descriptors-and-local-descriptor-aggregation-methods)** (image-wise descriptors).
- It implements loop closing via **[descriptor aggregators](#supported-global-descriptors-and-local-descriptor-aggregation-methods)** such as visual Bag of Words (BoW, iBow), Vector of Locally Aggregated Descriptors (VLAD) and other modern **[global descriptors](#supported-global-descriptors-and-local-descriptor-aggregation-methods)** (image-wise descriptors).
- It provides a **[dense reconstruction pipeline](#dense-reconstruction-pipeline)** when depth images are provided.
- It collects many other useful VO and SLAM tools.

**Main Scripts**:
Expand Down Expand Up @@ -178,6 +180,10 @@ Train the vocabulary by using the script `test/loopclosing/test_gen_dbow_voc_fro

**VLAD vocabulary generation**
Train the vocabulary by using the script `test/loopclosing/test_gen_vlad_voc_from_des_array.py`

### Dense reconstruction pipeline

Dense reconstruction is disabled by default. You can disable it by setting `kUseVolumetricIntegration=False` in `parameters.py`. At present, it works with RGBD datasets or when a depth image is available at each frame.

### Save and reload a map

Expand Down
2 changes: 1 addition & 1 deletion main_slam.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@

# Select your loop closing configuration (see the file loop_detector_configs.py). Set it to None to disable loop closing.
# LoopDetectorConfigs: DBOW2, DBOW3, etc.
loop_detection_config = LoopDetectorConfigs.OBINDEX2
loop_detection_config = LoopDetectorConfigs.DBOW3
Printer.green('loop_detection_config: ',loop_detection_config)

# create SLAM object
Expand Down
2 changes: 1 addition & 1 deletion main_vo.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@



kUseRerun = False
kUseRerun = True
# check rerun does not have issues
if kUseRerun and not Rerun.is_ok():
kUseRerun = False
Expand Down
8 changes: 6 additions & 2 deletions mplot_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* along with PYSLAM. If not, see <http://www.gnu.org/licenses/>.
"""

import sys
import time
import os
import numpy as np
Expand All @@ -32,9 +33,10 @@

#import multiprocessing as mp
import torch.multiprocessing as mp
from utils_sys import Logging
from utils_sys import Logging, locally_configure_qt_environment
from utils_mp import MultiprocessingManager



kPlotSleep = 0.04
kVerbose = False
kDebugAndPrintToFile = True
Expand Down Expand Up @@ -152,6 +154,7 @@ def quit(self):

def init(self, figure_num, lock):
lock.acquire()
locally_configure_qt_environment()
if kVerbose:
print(mp.current_process().name,"initializing...")
self.fig = plt.figure(figure_num)
Expand Down Expand Up @@ -326,6 +329,7 @@ def quit(self):

def init(self, figure_num, lock):
lock.acquire()
locally_configure_qt_environment()
if kVerbose:
print(mp.current_process().name, "initializing...")
self.fig = plt.figure(figure_num)
Expand Down
2 changes: 2 additions & 0 deletions qimage_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import cv2
import time

from utils_sys import Logging, locally_configure_qt_environment

class Resizer:
def __init__(self, window, name):
Expand Down Expand Up @@ -65,6 +66,7 @@ def quit(self):
print(f'QimageViewer closed')

def init(self):
locally_configure_qt_environment()
self.app = QApplication([]) # Initialize the application
self.image_map = {} # name -> (label,window)
self.key
Expand Down
17 changes: 10 additions & 7 deletions qtplot_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import torch.multiprocessing as mp
from utils_mp import MultiprocessingManager

from utils_sys import locally_configure_qt_environment

class FigureNum:
figure_num = 0

Expand Down Expand Up @@ -117,7 +119,7 @@ def quit(self):

def init(self, figure_num, lock):
lock.acquire()

locally_configure_qt_environment()
self.app = pg.mkQApp() # Create a PyQtGraph application
self.win = pg.PlotWidget(title=self.title) # Create a plot widget
self.legend = pg.LegendItem()
Expand Down Expand Up @@ -250,11 +252,12 @@ def get_values(delta):
xmajor = 10**(log)
return xminor, xmajor

xminor, xmajor = get_values(deltax)
yminor, ymajor = get_values(deltay)

self.win.getAxis('left').setTickSpacing(ymajor, yminor) # Y-axis: major and minor ticks
self.win.getAxis('bottom').setTickSpacing(xmajor, xminor) # X-axis: major and minor ticks
if deltax > 0 and deltay > 0:
xminor, xmajor = get_values(deltax)
yminor, ymajor = get_values(deltay)

self.win.getAxis('left').setTickSpacing(ymajor, yminor) # Y-axis: major and minor ticks
self.win.getAxis('bottom').setTickSpacing(xmajor, xminor) # X-axis: major and minor ticks

def setAxis(self):
if self.axis_computed:
Expand Down Expand Up @@ -440,7 +443,7 @@ def quit(self):

def init(self, figure_num, lock):
lock.acquire()

locally_configure_qt_environment()
self.app = pg.mkQApp() # Create a PyQtGraph application
#self.win = gl.GLViewWidget()
self.win = CustomGLViewWidget()
Expand Down
17 changes: 17 additions & 0 deletions thirdparty/pydbow3/modules/dbow3/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ message("LIB_INSTALL_DIR: ${LIB_INSTALL_DIR}")
# Build type
#------------------------------------------------------

# Generate file compile_commands.json in our build folder: it contains the full command line to compile individual source files
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)


IF(NOT CMAKE_BUILD_TYPE )
SET( CMAKE_BUILD_TYPE "Release" )
ENDIF()
Expand Down Expand Up @@ -118,6 +122,17 @@ set(EXTRA_EXE_LINKER_FLAGS "")
set(EXTRA_EXE_LINKER_FLAGS_RELEASE "")
set(EXTRA_EXE_LINKER_FLAGS_DEBUG "")


set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")

if(USE_MARCH_NATIVE AND NOT "${ARCH}" MATCHES "arm" AND "${CMAKE_SYSTEM_NAME}" MATCHES "Linux")
message(STATUS "Build with -march=native")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native -O3")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=native -O3")
endif()


IF(CMAKE_COMPILER_IS_GNUCXX OR MINGW)
set(ENABLE_PROFILING OFF CACHE BOOL "Enable profiling in the GCC compiler (Add flags: -g -pg)")
set(USE_OMIT_FRAME_POINTER ON CACHE BOOL "Enable -fomit-frame-pointer for GCC")
Expand Down Expand Up @@ -214,8 +229,10 @@ ELSE() # MSVC


ENDIF()#END OF COMPILER SPECIFIC OPTIONS

SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS} ${EXTRA_C_FLAGS_RELEASE}")
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS} ${EXTRA_C_FLAGS_DEBUG}")

# SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -std=c++11")
# SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -std=c++11")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELEASE} ${CMAKE_C_FLAGS_DEBUG}")
Expand Down
14 changes: 14 additions & 0 deletions utils_sys.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,3 +400,17 @@ def set_rlimit():
# Confirm the change
soft_limit, hard_limit = resource.getrlimit(resource.RLIMIT_NOFILE)
print(f"set_rlimit(): Updated soft limit: {soft_limit}, hard limit: {hard_limit}")


# To fix this issue under linux: https://forum.qt.io/topic/119109/using-pyqt5-with-opencv-python-cv2-causes-error-could-not-load-qt-platform-plugin-xcb-even-though-it-was-found
def locally_configure_qt_environment():
ci_and_not_headless = False # Default value in case the import fails
try:
from cv2.version import ci_build, headless
ci_and_not_headless = ci_build and not headless
except ImportError:
pass # Handle the case where cv2.version does not exist

if sys.platform.startswith("linux") and ci_and_not_headless:
os.environ.pop("QT_QPA_PLATFORM_PLUGIN_PATH", None) # Remove if exists
os.environ.pop("QT_QPA_FONTDIR", None) # Remove if exists

0 comments on commit 5e799cd

Please sign in to comment.