ouster.sdk.examples¶
Module contents¶
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.
Submodules¶
ouster.sdk.examples.cluster_example¶
ouster.sdk.examples.colormaps¶
Copyright (c) 2021, Ouster, Inc. All rights reserved.
Ouster spezia colormap
- colorize(image)[source]¶
Use Ouster spezia colormap to get from gray to color space.
- Parameters:
image (
ndarray) – 2D array of values in the range [0, 1]- Returns:
Array of RGB values of the same dimension selected from the color map
- normalize(data, percentile=0.05)[source]¶
Normalize and clamp data for better color mapping.
This is a utility function used ONLY for the purpose of 2D image visualization. The resulting values are not fully reversible because the final clipping step discards values outside of [0, 1].
- Parameters:
data (
ndarray) – array of data to be transformed for visualizationpercentile (
float) – values in the bottom/top percentile are clamped to 0 and 1
- Returns:
An array of doubles with the same shape as
imagewith values normalized to the range [0, 1].
ouster.sdk.examples.core¶
Copyright (c) 2021, Ouster, Inc. All rights reserved.
Executable examples for using the core sensor APIs.
This module has a rudimentary command line interface. For usage, run:
$ python -m ouster.sdk.examples.core -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(sensor_hostname)[source]¶
Configure sensor params given hostname
- Parameters:
hostname – hostname of the sensor
sensor_hostname (str)
- Return type:
None
- fetch_sensor_info(sensor_hostname)[source]¶
Fetch sensor info 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 sensor info and write it to disk for use with recorded data streams.
- Parameters:
hostname – hostname of the sensor
sensor_hostname (str)
- 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 sensorlidar_port (
int) – UDP port to listen on for lidar datarange_min (
int) – range minimum in meters
- Return type:
None
- get_fname_base(info)[source]¶
- Return type:
str- Parameters:
info (SensorInfo)
- live_plot_reflectivity(hostname, lidar_port=7502)[source]¶
Display reflectivity from live sensor
- Parameters:
hostname (
str) – hostname of the sensorlidar_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 frame as 3D points
- Parameters:
hostname (
str) – hostname of the sensorlidar_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 sensorlidar_port (
int) – UDP port to listen on for lidar dataimu_port (
int) – UDP port to listen on for imu datan_seconds (
int) – max seconds of time to record. (Ctrl-Z correctly closes streams)
- Return type:
None
ouster.sdk.examples.lidar_frame¶
- lidar_frame_example(info)[source]¶
- Return type:
- Parameters:
info (SensorInfo)
ouster.sdk.examples.lidar_scan¶
Copyright (c) 2024, Ouster, Inc. All rights reserved.
Deprecated module. Use ouster.sdk.examples.lidar_frame instead.
ouster.sdk.examples.open3d_example¶
Copyright (c) 2021, Ouster, Inc. All rights reserved.
Ouster Open3D visualizer
- canvas_set_image_data(pic, img_data)[source]¶
Set 2D image data to 2D canvas.
- Parameters:
pic (
TriangleMesh) – 2D canvas creates withcreate_canvas()img_data (
ndarray) – image data RGB (i.e. shape[h, w, 3])
- Return type:
None
- 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 withcreate_canvas()camera_params (
PinholeCameraParameters) – current open3d camera parameters
- Return type:
None
- 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
- 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]vis (Visualizer)
- viewer_3d(frames, paused=False)[source]¶
Render one frame 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 – frame number in a given pcap file (satrs from 0)
frames (FrameSetSource)
paused (bool)
- Return type:
None
ouster.sdk.examples.osf¶
- add_objects_to_frame(frame=None)[source]¶
Populate a LidarFrame with example Object instances.
- Parameters:
frame – optional LidarFrame to update directly.
- osf_get_sensors_info(osf_file)[source]¶
Read Lidar Sensors info from an OSF file.
Shows metadata for all sensors found in an OSF file.
- Parameters:
osf_file (
str) – path to osf file.- Return type:
None
- osf_read_frames(osf_file, limit=10)[source]¶
Read Lidar Frames from an OSF file.
Shows frames for each sensor in time order stored in the OSF File.
- Parameters:
osf_file (
str) – path to osf file.limit (int)
- Return type:
None
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_frame(source_file, num=0, visualize=True)[source]¶
Render one frame from a pcap file in the Open3D viewer.
- Parameters:
source – path to pcap
num (
int) – frame number in a given pcap file (satrs from 0)visualize (
bool) – when False, return xyz array without opening a windowsource_file (str)
- pcap_display_xyz_points(source_file, num=0, plot=True)[source]¶
Plot point cloud using matplotlib or return xyz/colors when plot is False.
- Parameters:
source_file (str)
num (int)
plot (bool)
- pcap_query_frame(source_file, num=0)[source]¶
Example: Query available fields in LidarFrame
- Parameters:
source_file (
str) – Path to pcap filenum (
int) – frame number in a given pcap file (satrs from 0)
- pcap_read_packets(source_file, num=0)[source]¶
Basic read packets example from pcap file.
- Parameters:
source_file (
str) – Path to pcap file.num (
int) – Unused. Included for CLI parity.
- pcap_to_las(source_file, num=0, las_dir='.', las_base='las_out', las_ext='las')[source]¶
Write frames from a pcap to las files (one per lidar frame). :rtype:
None- Parameters:
source_file (str)
num (int)
las_dir (str)
las_base (str)
las_ext (str)
- Return type:
None
ouster.sdk.examples.reference¶
Copyright (c) 2021, Ouster, Inc. All rights reserved.
Reference implementations of common operations.
- 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 metadatafield (
ndarray) – Staggered data as a H x W numpy array
- Return type:
ndarray- Returns:
Destaggered data as a H x W numpy array
- xyz_proj_beam_to_sensor_transform(metadata, frame)[source]¶
Computes a point cloud from a frame 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 frameframe (
LidarFrame) – 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, frame)[source]¶
Computes a point cloud from a frame 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 frameframe (
LidarFrame) – A frame of lidar data
- Return type:
ndarray- Returns:
A H x W x 3 array of point coordinates
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