Module ouster.sdk.examples

Copyright (c) 2021, Ouster, Inc. All rights reserved.

Code examples for using the Ouster SDK.

These modules are provided for documentation and testing purposes only, and should not be considered a stable public API.


Client Examples ouster.sdk.examples.client

Copyright (c) 2021, Ouster, Inc. All rights reserved.

Executable examples for using the sensor client APIs.

This module has a rudimentary command line interface. For usage, run:

$ python -m ouster.sdk.examples.client -h
configure_dual_returns(hostname)[source]

Configure sensor to use dual returns profile given hostname

Parameters

hostname (str) – hostname of the sensor

Return type

None

configure_sensor_params(hostname)[source]

Configure sensor params given hostname

Parameters

hostname (str) – hostname of the sensor

Return type

None

fetch_metadata(hostname)[source]

Fetch metadata from a sensor and write it to disk.

Accurately reconstructing point clouds from a sensor data stream requires access to sensor calibration and per-run configuration like the operating mode and azimuth window.

The client API makes it easy to read metadata and write it to disk for use with recorded data streams.

Parameters

hostname (str) – hostname of the sensor

Return type

None

filter_3d_by_range_and_azimuth(hostname, lidar_port=7502, range_min=2)[source]

Easily filter 3D Point Cloud by Range and Azimuth Using the 2D Representation

Parameters
  • hostname (str) – hostname of sensor

  • lidar_port (int) – UDP port to listen on for lidar data

  • range_min (int) – range minimum in meters

Return type

None

live_plot_reflectivity(hostname, lidar_port=7502)[source]

Display reflectivity from live sensor

Parameters
  • hostname (str) – hostname of the sensor

  • lidar_port (int) – UDP port to listen on for lidar data

Return type

None

plot_xyz_points(hostname, lidar_port=7502)[source]

Display range from a single scan as 3D points

Parameters
  • hostname (str) – hostname of the sensor

  • lidar_port (int) – UDP port to listen on for lidar data

Return type

None

record_pcap(hostname, lidar_port=7502, imu_port=7503, n_seconds=10)[source]

Record data from live sensor to pcap file.

Note that pcap files recorded this way only preserve the UDP data stream and not networking information, unlike capturing packets directly from a network interface with tools like tcpdump or wireshark.

See the API docs of pcap.record() for additional options for writing pcap files.

Parameters
  • hostname (str) – hostname of the sensor

  • lidar_port (int) – UDP port to listen on for lidar data

  • imu_port (int) – UDP port to listen on for imu data

  • n_seconds (int) – max seconds of time to record. (Ctrl-Z correctly closes streams)

Return type

None


PCAP Examples ouster.sdk.examples.pcap

Copyright (c) 2021, Ouster, Inc. All rights reserved.

Executable examples for using the pcap APIs.

This module has a rudimentary command line interface. For usage, run:

$ python -m ouster.sdk.examples.pcap -h
pcap_3d_one_scan(source, metadata, num=0)[source]

Render one scan from a pcap file in the Open3D viewer.

Parameters
  • source (PacketSource) – PacketSource from pcap

  • metadata (SensorInfo) – associated SensorInfo for PacketSource

  • num (int) – scan number in a given pcap file (satrs from 0)

Return type

None

pcap_display_xyz_points(source, metadata, num=0)[source]

Plot point cloud using matplotlib.

Return type

None

pcap_to_csv(source, metadata, num=0, csv_dir='.', csv_base='pcap_out', csv_ext='csv')[source]

Write scans from a pcap to csv files (one per lidar scan).

The number of saved lines per csv file is always H x W, which corresponds to a full 2D image representation of a lidar scan.

Each line in a csv file is (for LEGACY profile):

TIMESTAMP, RANGE (mm), SIGNAL, NEAR_IR, REFLECTIVITY, X (mm), Y (mm), Z (mm)

If csv_ext ends in .gz, the file is automatically saved in compressed gzip format. numpy.loadtxt() can be used to read gzipped files transparently back to numpy.ndarray.

Parameters
  • source (PacketSource) – PacketSource from pcap

  • metadata (SensorInfo) – associated SensorInfo for PacketSource

  • num (int) – number of scans to save from pcap to csv files

  • csv_dir (str) – path to the directory where csv files will be saved

  • csv_base (str) – string to use as the base of the filename for pcap output

  • csv_ext (str) – file extension to use, “csv” by default

Return type

None

pcap_to_las(source, metadata, num=0, las_dir='.', las_base='las_out', las_ext='las')[source]

Write scans from a pcap to las files (one per lidar scan).

Return type

None

pcap_to_pcd(source, metadata, num=0, pcd_dir='.', pcd_base='pcd_out', pcd_ext='pcd')[source]

Write scans from a pcap to pcd files (one per lidar scan).

Return type

None

pcap_to_ply(source, metadata, num=0, ply_dir='.', ply_base='ply_out', ply_ext='ply')[source]

Write scans from a pcap to ply files (one per lidar scan).

Return type

None

pcap_query_scan(source, metadata, num=0)[source]

Example: Query available fields in LidarScan

Parameters
  • source (PacketSource) – PacketSource from pcap

  • metadata (SensorInfo) – associated SensorInfo for PacketSource

  • num (int) – scan number in a given pcap file (satrs from 0)

Return type

None

pcap_read_packets(source, metadata, num=0)[source]

Basic read packets example from pcap file.

Return type

None

main()[source]

Pcap examples runner.


Open3D Examples ouster.sdk.examples.open3d

Copyright (c) 2021, Ouster, Inc. All rights reserved.

Ouster Open3D visualizer

view_from(vis, from_point, to_point=array([0, 0, 0]))[source]

Helper to setup view direction for Open3D Visualiser.

Parameters
  • from_point (ndarray) – camera location in 3d space as [x,y,z]

  • to_point (ndarray) – camera view direction in 3d space as [x,y,z]

create_canvas(w, h)[source]

Create canvas for 2D image.

Parameters
  • w (int) – width of the 2D image in screen coords (pixels)

  • h (int) – height of the 2D image in screen coords (pixels)

Return type

TriangleMesh

canvas_set_viewport(pic, camera_params)[source]

Set the position of the 2D image in space so it seems as static.

The method should be called on every animation update (animation callback) before rendering so the 2D mesh with texture always appear in the position that would seem “static” for the observer of the scene through the current camera parameters.

Parameters
  • pic (TriangleMesh) – canvas with 2D image, created with create_canvas()

  • camera_params (PinholeCameraParameters) – current open3d camera parameters

Return type

None

canvas_set_image_data(pic, img_data)[source]

Set 2D image data to 2D canvas.

Parameters
  • pic (TriangleMesh) – 2D canvas creates with create_canvas()

  • img_data (ndarray) – image data RGB (i.e. shape [h, w, 3])

Return type

None

viewer_3d(scans, paused=False)[source]

Render one scan in Open3D viewer from pcap file with 2d image.

Parameters
  • pcap_path – path to the pcap file

  • metadata_path – path to the .json with metadata (aka SensorInfo)

  • num – scan number in a given pcap file (satrs from 0)

Return type

None


Examples PointViz ouster.sdk.examples.viz

Copyright (c) 2021, Ouster, Inc. All rights reserved.

Example of custom visualizer use.

Intended to run with python -m ouster.sdk.examples.viz

make_checker_board(square_size, reps)[source]

Makes a test checker board image.

main()[source]

PointViz visualizer examples.

Reference Code ouster.sdk.examples.reference

Copyright (c) 2021, Ouster, Inc. All rights reserved.

Reference implementations of common operations.

xyz_proj_beam_to_sensor_transform(metadata, scan)[source]

Computes a point cloud from a scan as numpy array.

This is a reference implementation that follows the calculations from Section X of the Software User Manual exactly. Output is a point cloud in the sensor frame with points arranged in column-major order, with coordinates in meters.

Parameters
  • metadata (SensorInfo) – Sensor metadata associated with the scan

  • scan (LidarScan) – A frame of lidar data

Return type

ndarray

Returns

A H x W x 3 array of point coordinates

xyz_proj_origin_to_origin_mm(metadata, scan)[source]

Computes a point cloud from a scan as numpy array

This is the old reference implementation that follows the calculations from Section 3.1.2 of the FW 2.0 Software User Manual exactly for OS-0, OS-1, and OS-2 sensors. The output is a point cloud in the sensor frame with points arranged in column-major order, with coordinates in meters.

Parameters
  • metadata (SensorInfo) – Sensor metadata associated with the scan

  • scan (LidarScan) – A frame of lidar data

Return type

ndarray

Returns

A H x W x 3 array of point coordinates

destagger(pixel_shift_by_row, field)[source]

Reference implementation for destaggering a field of data.

In the default staggered representation, each column corresponds to a single timestamp. In the destaggered representation, each column corresponds to a single azimuth angle, compensating for the azimuth offset of each beam.

Destaggering is used for visualizing lidar data as an image or for algorithms that exploit the structure of the lidar data, such as beam_uniformity in ouster_viz, or computer vision algorithms.

Parameters
  • pixel_shift_by_row (List[int]) – List of pixel shifts by row from sensor metadata

  • field (ndarray) – Staggered data as a H x W numpy array

Return type

ndarray

Returns

Destaggered data as a H x W numpy array