Skip to main content

roboflex.realsense

Support for the Realsense D435 camera. We really just wrap the sdk and encode data into messages. It might work with other D4** cameras - YMMV.

System Dependencies

Sort of: none. We use cmake to build. If find_package(realsense2) fails (meaning cmake can't find some system-installed version of realsense2), we fetch and build it.

Install

pip install roboflex.realsense

Import

import roboflex.realsense as rr

Nodes

There is only one: RealsenseSensor

You can use a class method to discover the serial numbers of all the cameras currently connected to your computer:

rr.RealsenseSensor.get_connected_device_serial_numbers()

There are two ways to instantiate realsense sensors:

  1. Via the constructor - you must know the serial number. See below for documentation of the Config type.

     sensor = rr.RealsenseSensor(
         serial_number: str,
         config: rr.Config,
         name: str = "RealsenseSensor",
     )
    
  2. Via a class method - if you have a single realsense attached, this is the easiest way - you don't even have to know the serial number.

     sensor = rr.RealsenseSensor.get_one_sensor(
         config: rr.Config,
         name: str = "RealsenseSensor",
     )
    

Use it like so:

# must be started!
sensor.start()

# You can get the serial number:
sensor.serial_number -> str

# You can get the configuration back:
sensor.config -> rr.Config

# You can get the two camera-k matrices:
sensor.depth_camera_k -> np.array
sensor.color_camera_k -> np.array

# You can get various device values:
sensor.width_pixels_color -> int
sensor.height_pixels_color -> int
sensor.width_pixels_depth -> int
sensor.height_pixels_depth -> int
sensor.fps_color -> int
sensor.fps_depth -> int

# You can manually trigger a message event:
# (for the most part you won't need this - only
# if you have special need to control the message
# production), and don't want to use "start".
sensor.produce()

# You can turn the IR laser off and on
sensor.set_laser_on_off(False)
sensor.set_laser_on_off(True)

Messages

RealsenseSensor produces a single message type: RealsenseFrameset.

from roboflex.realsense import RealsenseFrameset

API:

# the timestamp just before reading from device
message.t0 -> Float

# the timestamp just after reading from device
message.t1 -> Float

# numpy array of shape=(height, width, 3), dtype=uint8
message.rgb -> np.ndarray

# numpy array of shape=(height, width), dtype=uint16
message.depth -> np.ndarray

# numpy array of shape=(height, width), dtype=uint8
message.ir1 -> np.ndarray

# numpy array of shape=(height, width), dtype=uint8
message.ir2 -> np.ndarray

# which camera (if any) the frame is aligned to
message.aligned_to -> rr.CameraType

# the serial number of the camera that produced this frameset
message.serial_number -> str

# the color camera k of the camera that produced this frameset
message.camera_k_rgb -> numpy array of (3, 3)

# the depth camera k of the camera that produced this frameset
message.camera_k_depth -> numpy array of (3, 3)

# the ir1 camera k of the camera that produced this frameset
message.camera_k_ir1 -> numpy array of (3, 3)

# the ir2 camera k of the camera that produced this frameset
message.camera_k_ir2 -> numpy array of (3, 3)

# the index, from the device, of this frameset
message.frame_number -> int

# the timestamp, from the device, of this frameset, in epoch seconds
message.timestamp -> float

DYNOFLEX:

d = DynoFlex.from_msg(message)

# the timestamp just before reading from device
d["t0"] -> Double

# the timestamp just after reading from device
d["t1"] -> Double

# numpy array of shape=(height, width, 3), dtype=uint8
d["rgb"] -> np.ndarray

# numpy array of shape=(height, width), dtype=uint16
d["depth"] -> np.ndarray

# numpy array of shape=(height, width), dtype=uint8
d["ir1"] -> np.ndarray

# numpy array of shape=(height, width), dtype=uint8
d["ir2"] -> np.ndarray

# which camera (if any) the frame is aligned to
d["aligned_to"] -> rr.CameraType

# the serial number of the camera that produced this frameset
d["serial_number"] -> str

# the color camera k of the camera that produced this frameset
d["camera_k_rgb"] -> numpy array of (3, 3)

# the depth camera k of the camera that produced this frameset
d["camera_k_depth"] -> numpy array of (3, 3)

# the camera k of the infrared camera 1 that produced this frameset
d["camera_k_ir1"] -> numpy array of (3, 3)

# the camera k of the infrared camera 2 that produced this frameset
d["camera_k_ir2"] -> numpy array of (3, 3)

# the index, from the device, of this frameset
d["n"] -> int

# the timestamp, from the device, of this frameset, in epoch seconds
d["t"] -> float

Other

Some types used for configuration

Some enums:

CameraType:
    RGB,
    DEPTH,
    IR1,    # raw infrared camera1
    IR2     # raw infrared camera2

# You can OR these together like so:

my_cameras = camera_type_or([CameraType.RGB, CameraType.DEPTH, etc])

# You can test for camera types:

has_rgb = camera_type_contains(my_camera_type, CameraType.RGB)

CameraAlignment:
    NONE,
    RGB,
    DEPTH

D400VisualPreset:
    CUSTOM,
    DEFAULT,
    HAND,
    HIGH_ACCURACY,
    HIGH_DENSITY,
    MEDIUM_DENSITY

TemporalFilterParameters:

f = rr.TemporalFilterParameters(
    alpha: float = 0.4,
    delta: float = 20.0,
    persistance_control: int = 7,
)

f.alpha -> float
f.delta -> float
f.persistance_control -> int

Config:

# all paramters are optional - defaults shown below
c = rr.Config(
    camera_type: rr.CameraType = CameraType.RGB | CameraType.DEPTH,
    align_to: rr.CameraAlignment = rr.CameraAlignment.NONE,
    prioritize_ae: Bool = False,
    rgb_settings: Dict[str, int] = {
        "fps": 0,
        "width": 0,
        "height": 0,
    },
    depth_settings: Dict[str, int] = {
        "fps": 0,
        "width": 0,
        "height": 0,
    },
    depth_visual_preset: rr.D400VisualPreset = rr.D400VisualPreset.DEFAULT,
    temporal_filter_parameters: rr.TemporalFilterParameters = None,
    hole_filling_mode: Optional[int] = None,
    decimation_filter: Optional[int] = None,
)

# which actual cameras are in use - this a bitmask, OR-ed together
c.camera_type -> rr.CameraType

# which camera the frames will be aligned to (if any)
c.align_to -> rr.CameraAligment

# When `true`, allows fps to drop in order to better expose
# frames, such as in dimly lit environments
c.prioritize_ae -> Bool

# fps, height, and width of the color camera
c.rgb_settings -> Dict[str, int]

# fps, height, and width of the depth camera
c.depth_settings -> Dict[str, int]

# the depth camera visual preset
c.depth_visual_preset -> rr.D400VisualPreset

# the temporal filter, if any - can be None
c.temporal_filter_parameters -> rr.TemporalFilterParameters

# the 'hole filling mode', if any - can be None
# 0: fill_from_left
# 1: farthest_from_around
# 2: nearest_from_around
c.hole_filling_mode -> int

# NOTE!
The realsense camera supports many more settings, such as laser power, etc. If there's something you want supported that's not
here, just let me know.

Metadata

Release files for roboflex.realsense 0.1.12

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for roboflex.realsense 0.1.12
File Size Uploaded
roboflex_realsense-0.1.12.tar.gz 19.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for roboflex.realsense 0.1.12
File Interpreter ABI Platform
roboflex_realsense-0.1.12-cp311-cp311-macosx_15_0_arm64.whl CPython 3.11 CPython 3.11 macOS 15.0+ ARM64 Details

Total release size: 2.8 MB

Release files / roboflex_realsense-0.1.12.tar.gz

Download URL roboflex_realsense-0.1.12.tar.gz
Size 19.1 kB
Tags Source
SHA-256 checksum
How to use checksums
355f2f2656457dba9378b1a52105c5ee679087ce6f8f1a47bbc2a3c8715125fb
BLAKE2b-256 checksum
How to use checksums
c0c1b023d55cd622d0cae8245874e6f5f02495870caab9218b55b553d3861fca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.5

Release files / roboflex_realsense-0.1.12-cp311-cp311-macosx_15_0_arm64.whl

Download URL roboflex_realsense-0.1.12-cp311-cp311-macosx_15_0_arm64.whl
Size 2.8 MB
Tags CPython 3.11 macOS 15.0+ ARM64
SHA-256 checksum
How to use checksums
9b4c2dab1315e076230744f9fa57fdedd5d06ea50ed02de707d152fde38d58ed
BLAKE2b-256 checksum
How to use checksums
8448a0753012f754b884688f047f26ae2198581d3c526e2295d5487b728e327c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.5

Release history Release notifications | RSS feed

This release

0.1.12 This release

2 release files

0.1.11

2 release files

0.1.10

2 release files

0.1.9

2 release files

0.1.6

1 release file

0.1.5

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page