RealSense

enumerate_realsense_cameras()

Enumerate Intel realsense cameras attached to a device

Typical usage:

serial_numbers = []
serial_number = edgeiq.enumerate_realsense_cameras()
Returns

list type string – The serial numbers of connected realsense cameras

class RealSense(device_serial_number=None)

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. Only usb 3.0 connections are supported.

Typical usage:

try:
    with edgeiq.RealSense() as video_stream,
            edgeiq.Streamer() as streamer:
        time.sleep(2.0)

<get distances to objects>
video_stream.start()

while True:
    depth_image, color_image = video_stream.read()
    results = obj_detect.detect_objects(color_image, confidence_level=.5)

    for prediction in results.predictions:
            distance = video_stream.compute_object_distance(prediction.box,depth_image)
Parameters

device_serial_number (string) – The serial number of the realsense device you want to use obtained from enumerate_realsense_cameras() function

start()

Start Realsense camera

Returns

self

read()

Return the most recent color_image and depth_image.

Returns

numpy arrays – color_image and depth_image

render_depth_image(depth_image)

Produce a depth_colormap from depth_image where the closer an object is it will appear bluer in the map and the farther away more red

Parameters

depth_image (numpy array) – depth channel from the camera stream

Returns

numpy array – color map derived from depth_image

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

Capture the region of interest (roi) within frame or image. If min equals None color pixels further than the max are removed. If max equals None color pixels closer than the min will be removed. Other wise color pixels closer than the min and further than the max are removed. Removed pixels will be replaced by grey pixels who’s intensity can be adjusted with the shade parameter (0 - 255), where 0 equals black and 255 equals white. Min and Max distances are measured in meters

Parameters
  • depth_image (numpy array) – The depth channel informatin from the camera

  • color_image (numpy array) – The color image from the camera

  • min (float) – minimum distance in meters of the roi boundry, color pixels closer than this value will be removed and replaced by gray pixels

  • max (float) – maxium distance in meters of the roi boundry, color pixels further than this value will be removed and replaced by gray pixels

  • shade (integer) – shade of gray pixel used to replace the color pixels from the image, range is 0-255.

Returns

numpy array – The roi image.

compute_object_distance(box, depth_image)

Get distance in meters to a detected object.

Parameters
  • box (bounding box class) – A property of ObjectDetectionResults class, it is the rectangle around the detected object

  • depth_image (numpy array) – The depth channel informatin from the camera

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
  • box1 (bounding box class) – A property of ObjectDetectionResults class, it is the rectangle around the detected object

  • box2 (bounding box class) – A property of ObjectDetectionResults class, it is the rectangle around a second detected object

Returns

float – The distance in meters between the detected objects

stop()

Stop Realsense camera