Skip to main content

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

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyrealsense-1.4.tar.gz (12.9 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page