raulmur / ORB_SLAM2

Real-Time SLAM for Monocular, Stereo and RGB-D Cameras, with Loop Detection and Relocalization Capabilities
Other
9.33k stars 4.69k forks source link

Cython bindings and further modifications #960

Closed apoorvkh closed 2 years ago

apoorvkh commented 3 years ago

Modifications:

Compilation instructions: Add ORB_SLAM2/lib to PYTHONPATH and LD_LIBRARY_PATH environment variables Run ./build.sh && ./build_python.sh

To use in Python:

import orbslam2

vocab_file = 'ORB_SLAM2/Vocabulary/ORBvoc.bin'
settings_file = 'ORB_SLAM2/Examples/RGB-D/TUM3.yaml'
mode = 'rgbd' # or 'monocular' or 'stereo'
init_pose = np.eye(4, dtype=np.float32) # specify camera intrinsics for initial view
use_viewer = True

slam_system = orbslam2.SLAM(vocab_file, settings_file, mode, init_pose, use_viewer)

# For each SLAM step
# frame : np.array(shape : [w, h, c], dtype : np.uint8)
# depth_frame : np.array(shape : [w, h], dtype : np.float32)
pose, tracked_map_points = self.slam_system.track(frame, depth_frame)

# when finished
slam_system.shutdown()

See cdef class SLAM in ORB_SLAM2/python/orbslam2.pyx for other Python functions.