RealSense

enumerate_realsense_cameras()

Enumerate Intel RealSense cameras attached to a device.

Typical usage:

serial_numbers = edgeiq.enumerate_realsense_cameras()

cameras = []
for serial_number in serial_numbers:
    cameras.append(RealSense(device_serial_number=serial_number)
Returns

list of strings – The serial numbers of connected RealSense cameras.

class RealSenseFrame(depth_frame, color_frame, depth_scale)
property image

The color image data for this frame.

Returns

numpy array – The color image as a numpy array.

property depth

The depth data for this frame.

Returns

numpy array – The frame depth as a numpy array where each pixel has a corresponding float value representing depth in meters.

render_depth_image()

Produce a depth color map from the RealSense frame.

In the color map, closer objects will appear bluer and further objects will appear redder.

Returns

numpy array – The color map derived from the depth data.

roi(min=None, max=None, shade=160)

Capture the region of interest (ROI) within frame or image.

This function supports different behavior based on the inputs: * When only min is set pixels closer than min are removed. * When only max is set pixels further than max are removed. * When both min and max are set pixels closer than min and further than max are removed.

The removed pixels are replaced by values of the shade parameter in grayscale.

Parameters
  • min (float) – minimum distance in meters of the roi boundary

  • max (float) – maximum distance in meters of the roi boundary

  • shade (integer) – shade of gray used to replace the removed pixels from the image. Valid range is 0-255, where 0 is black and 255 is white.

Returns

numpy array – The image with only ROI in color and other pixels in grayscale.

compute_object_distance(obj, kernel_size=8, gaussian_sigma=3)

Get distance in meters to a detected object.

Parameters

obj (BoundingBox or tuple of x y coordinates.) – The object to get the distance to, either as a bounding box around the object or an x y coordinate.

:type kernel_size : int

Parameters

kernel_size – size of the roi matrix.For instance, kernel_size of 8 extracts a region (8,8) around the point / object center to filter

:type gaussian_sigma : int

:param gaussian_sigma : standard deviation of the gaussian kernel

Returns

float – The distance in meters to the detected object.

compute_distance_between_objects(box1, box2)

Get distance in meters between two detected objects in 3D space.

Parameters
Returns

float – The distance in meters between the detected objects.

get_serializable_realsense_frame()

Get a serializable version of RealSenseFrame.

RealSenseFrame is not serializable due to containing some objects from the pyrealsense2 library. The serializable version has reduced functionality.

Returns

.SerializableRealSenseFrame

class SerializableRealSenseFrame(depth_array, color_array, depth_scale)
compute_distance_between_objects(box1, box2)

Not supported by SerializableRealSenseFrame.

Raises

NotImplementedError

compute_object_distance(obj, kernel_size=8, gaussian_sigma=3)

Get distance in meters to a detected object.

Parameters

obj (BoundingBox or tuple of x y coordinates.) – The object to get the distance to, either as a bounding box around the object or an x y coordinate.

:type kernel_size : int

Parameters

kernel_size – size of the roi matrix.For instance, kernel_size of 8 extracts a region (8,8) around the point / object center to filter

:type gaussian_sigma : int

:param gaussian_sigma : standard deviation of the gaussian kernel

Returns

float – The distance in meters to the detected object.

property depth

The depth data for this frame.

Returns

numpy array – The frame depth as a numpy array where each pixel has a corresponding float value representing depth in meters.

get_serializable_realsense_frame()

Get a serializable version of RealSenseFrame.

RealSenseFrame is not serializable due to containing some objects from the pyrealsense2 library. The serializable version has reduced functionality.

Returns

.SerializableRealSenseFrame

property image

The color image data for this frame.

Returns

numpy array – The color image as a numpy array.

render_depth_image()

Produce a depth color map from the RealSense frame.

In the color map, closer objects will appear bluer and further objects will appear redder.

Returns

numpy array – The color map derived from the depth data.

roi(min=None, max=None, shade=160)

Capture the region of interest (ROI) within frame or image.

This function supports different behavior based on the inputs: * When only min is set pixels closer than min are removed. * When only max is set pixels further than max are removed. * When both min and max are set pixels closer than min and further than max are removed.

The removed pixels are replaced by values of the shade parameter in grayscale.

Parameters
  • min (float) – minimum distance in meters of the roi boundary

  • max (float) – maximum distance in meters of the roi boundary

  • shade (integer) – shade of gray used to replace the removed pixels from the image. Valid range is 0-255, where 0 is black and 255 is white.

Returns

numpy array – The image with only ROI in color and other pixels in grayscale.

class RealSenseMode(value)

Sensor Mode applied to Intel RealSense camera configuration.

The sensor mode determines the width, height and FPS of the Depth and RGB streams. The format is:

<rgb_width>x<rgb_height>_<depth_width>x<depth_height>_<fps>

RS_1920x1080_1280x720_30 = 0
RS_1280x720_1280x720_30 = 1
RS_848x480_848x480_30 = 2
class RealSense(device_serial_number=None, mode=<RealSenseMode.RS_1280x720_1280x720_30: 1>)

A set of methods that can be used with a RealSense camera(s) for getting the distances to objects, capturing regions of interest based on distance, displaying video streams and depth maps.

Typical usage:

from edgeiq import realsense

with edgeiq.realsense.RealSense() as video_stream:
    while True:
        rs_frame = video_stream.read()
        results = obj_detect.detect_objects(
                 rs_frame.image, confidence_level=.5)

        for prediction in results.predictions:
                distance = rs_frame.compute_object_distance(
                    prediction.box)
Parameters
  • device_serial_number (string) – The serial number of the realsense device to use obtained from the enumerate_realsense_cameras() function. If set to None the first discovered RealSense camera will be used.

  • mode (RealSenseMode) – The sensor mode for the RealSenseCamera

property mode

The sensor mode configured for this camera

start()

Start RealSense camera.

Returns

self

read()

Read the most recent depth and color frame data.

Returns

RealSenseFrame

stop()

Stop RealSense camera.