slamcore / slamcore-python

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Slamcore Python bindings

Slamcore Python bindings CI

These bindings wrap Slamcore C++ API allowing users to utilize Slamcore's implementation of the SLAM (Simultaneous Localization and Mapping) algorithm in Python.

Dependencies

The following dependencies must also be installed to build and use the bindings:

eigen3 mypy numpy pybind11 python slamcore_sdk wheel

Building

Install needed dependencies:

apt install libeigen3-dev && \
  python3 -m pip install setuptools "pybind11[global]" mypy numpy wheel

Configure the project:

mkdir build && cd build
cmake .. -DPYTHON_EXECUTABLE=$(which python3)

To build just the shared object, simply run:

make slamcore_python

To also build a wheel package, run the following:

make slamcore_python_wheel

Quickstart

To install the bindings, install the wheel package with pip:

python -m pip install python/*.whl

Uninstalling is the same as any other package:

python -m pip uninstall slamcore

Alternatively, it is possible to add the generated .so to your Python search path by appending the absolute directory to your PYTHONPATH:

export PYTHONPATH="${PYTHONPATH}:<path-to-slamcore-python>/build/python"

As a minimal example:

import slamcore

def print_pose(pose: slamcore.CameraPose):
    translation = pose.translation
    print(f"{translation[0]}, {translation[1]}, {translation[2]}")

cfg = slamcore.SystemConfiguration()
slam_system = slamcore.create_slam_system(cfg)

slam_system.open()

slam_system.set_stream_enabled(slamcore.Stream.Pose, True)
slam_system.register_pose_callback(print_pose)

slam_system.start()

while True:
    try:
        while slam_system.spin(0.1):
            continue # callback triggered
        else:
            logging.warning("timeout")
    except KeyboardInterrupt:
        break

slam_system.stop()

slam_system.close()

An example script can be found under examples/hello_world.py.

Running the tests

Alongside the source code, some pytest tests are provided. These run SLAM on an input dataset and exercise various features of the system.

They can be run as follows:

pytest -v --dataset <path-to-my-dataset> tests

Contact

https://www.slamcore.com/contact

About

License:BSD 3-Clause "New" or "Revised" License


Languages

Language:C++ 62.7%Language:Python 28.4%Language:CMake 9.0%