Skip to content

Commit

Permalink
small changes to examples, readme, add get/set device option
Browse files Browse the repository at this point in the history
  • Loading branch information
toinsson committed Dec 19, 2016
1 parent dec5036 commit 230a328
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 18 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Pyrealsense
Simple ctypes extension to the [librealsense](https://github.com/IntelRealSense/librealsense) library.
Simple [ctypes](https://docs.python.org/2/library/ctypes.html) extension to the [librealsense](https://github.com/IntelRealSense/librealsense) library.

## Dependencies

Expand All @@ -13,7 +13,7 @@ The library depends on [pycparser](https://github.com/eliben/pycparser) for pars

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

## import the package
import pyrealsense as pyrs
Expand All @@ -34,11 +34,12 @@ Different devices can be created from the `Device` class. They are defined by de

The available streams are either native or synthetic, and each one will create a property on the Device instancve 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.

## caveats
## Caveats
To this point, this wrapper has only been tested with:
- Python 2.x
- Linux architecture
- Ubuntu 16.04 LTS
- Python 2.7
- SR300 camera
- [librealsense v1.9.7](https://github.com/IntelRealSense/librealsense/tree/v1.9.7)

## build status
## Build Status
Ubuntu Trusty, python 2 and 3: [![Build Status](https://travis-ci.org/toinsson/pyrealsense.svg?branch=master)](https://travis-ci.org/toinsson/pyrealsense)
4 changes: 3 additions & 1 deletion examples/show_cv2.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import logging
logging.basicConfig(level=logging.INFO)

import time
import numpy as np
import cv2
import pyrealsense as pyrs

import ipdb; ipdb.set_trace()

pyrs.start()
dev = pyrs.Device()
Expand Down
6 changes: 5 additions & 1 deletion examples/show_matplotlib.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import pyrealsense as pyrs
import logging
logging.basicConfig(level=logging.INFO)

import matplotlib.pyplot as plt

import pyrealsense as pyrs

pyrs.start()
dev = pyrs.Device()

Expand Down
30 changes: 20 additions & 10 deletions pyrealsense/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ def stop():
class Device(object):
"""Camera device."""
def __init__(self,
device_id = 0,
streams = [ColourStream(), DepthStream(), PointStream(), CADStream()],
depth_control_preset = None,
ivcam_preset = None):
device_id = 0,
streams = [ColourStream(), DepthStream(), PointStream(), CADStream()],
depth_control_preset = None,
ivcam_preset = None):
super(Device, self).__init__()

global ctx
Expand All @@ -109,12 +109,6 @@ def __init__(self,
pp(lrs.rs_get_device_firmware_version, self.dev, ctypes.byref(e))))
_check_error();

## depth control preset
if depth_control_preset:
rsutilwrapper._apply_depth_control_preset(self.dev, depth_control_preset)
## ivcam preset
if ivcam_preset:
rsutilwrapper._apply_ivcam_preset(self.dev, ivcam_preset)

self.streams = streams
for s in self.streams:
Expand All @@ -126,6 +120,14 @@ def __init__(self,

lrs.rs_start_device(self.dev, ctypes.byref(e))

## depth control preset
if depth_control_preset:
rsutilwrapper._apply_depth_control_preset(self.dev, depth_control_preset)

## ivcam preset
if ivcam_preset:
rsutilwrapper._apply_ivcam_preset(self.dev, ivcam_preset)

## add stream property and intrinsics
for s in self.streams:
if s.native:
Expand All @@ -149,6 +151,14 @@ def wait_for_frame(self):
"""Block until new frames are available."""
lrs.rs_wait_for_frames(self.dev, ctypes.byref(e))

def get_device_option(self, option):
"""Get device option."""
return lrs.rs_get_device_option(self.dev, option, ctypes.byref(e))

def set_device_option(self, option, value):
"""Set device option."""
return lrs.rs_set_device_option(self.dev, option, ctypes.byref(e))

def _get_stream_intrinsics(self, stream):
_rs_intrinsics = rs_intrinsics()
lrs.rs_get_stream_intrinsics(
Expand Down

0 comments on commit 230a328

Please sign in to comment.