Skip to content

Simple ctypes extension to the librealsense library for Linux and Mac OS.

License

Notifications You must be signed in to change notification settings

MathijsNL/pyrealsense

 
 

Repository files navigation

PyRealsense

Simple ctypes extension to the librealsense library for Linux and Mac OS.

Dependencies

The library depends on pycparser for parsing the librealsense h files and extracting necessary enums and structures definitions. Numpy is used for generic data shuffling.

Installation

from PyPI:

pip install pyrealsense

from source:

pip install pycparser numpy
python setup.py install

Online Usage

## setup logging
import logging
logging.basicConfig(level = logging.INFO)

## import the package
import pyrealsense as pyrs

## start the service
pyrs.start()

## create a device from device id and streams of interest
cam = pyrs.Device(device_id = 0, streams = [pyrs.ColourStream(fps = 60)])

## wait for data and retrieve numpy array for ~1 second
for i in range(60):
    cam.wait_for_frame()
    print(cam.colour)

The server for Realsense devices is started with pyrs.start() which will printout the number of devices available.

Different devices can be created from the Device factory. They are created as their own class defined by device id, name, serial, firmware, as well as streams passed and camera presets. The default behaviour create a device with id = 0 and setup the colour, depth, pointcloud and colour_aligned_depth streams.

The available streams are either native or synthetic, and each one will create a property that exposes the current content of the frame buffer in the form of device.<stream_name>, where <stream_name> is colour, depth, points, cad or dac. To get access to new data, Device.wait_for_frame has to be called once per frame.

Offline Usage

## with connected device cam
from pyrealsense import offline
offline.save_depth_intrinsics(cam)
## previous device cam now offline
from pyrealsense import offline
offline.load_depth_intrinsics('610205001689')  # camera serial number
d = np.linspace(0, 1000, 480*640, dtype=np.uint16)
pc = offline.deproject_depth(d)

The module offline allows storing the rs_intrinsics and depth_scale of a device to disk, by default in the home directory in the file .pyrealsense. This can later be loaded and used to deproject depth data into pointcloud, which is useful to store raw video file and save some disk memory.

Examples

The examples are split based on the visualisation technology they require. One shows a still image with matplotlib, another one streams depth and color data with opencv, and the last one displays a live feed of the pointcloud with VTK.

Caveats

To this point, this wrapper is tested with:

  • librealsense v1.12.1
  • Ubuntu 16.04 LTS, Mac OS X 10.12.2 w/ SR300 camera
  • Mac OS X 10.12.3 w/ R200 camera

The offline module only supports a single camera.

Build Status

Ubuntu Trusty, python 2 and 3: Build Status

Possible Pull Requests

  • support for Windows
  • support for several cameras in offline module

About

Simple ctypes extension to the librealsense library for Linux and Mac OS.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 89.8%
  • C 10.2%