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.
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(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 sensorlidar_port (
int) – UDP port to listen on for lidar datarange_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 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 scan 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_scan
ouster.sdk.examples.open3d_example
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 withcreate_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 withcreate_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
ouster.sdk.examples.osf
- osf_read_scans(osf_file)[source]
Read Lidar Scans from an OSF file.
Shows scans for each sensor in time order stored in the OSF File.
- Parameters:
osf_file (
str) – path to osf file.- Return type:
None
- 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
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_file, num=0, visualize=True)[source]
Render one scan from a pcap file in the Open3D viewer.
- Parameters:
source – path to pcap
num (
int) – scan number in a given pcap file (satrs from 0)visualize (
bool) – when False, return xyz array without opening a window
- pcap_display_xyz_points(source_file, num=0, plot=True)[source]
Plot point cloud using matplotlib or return xyz/colors when plot is False.
- pcap_to_las(source_file, 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_file, 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_file, 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_file, num=0)[source]
Example: Query available fields in LidarScan
- Parameters:
source_file (
str) – Path to pcap filenum (
int) – scan number in a given pcap file (satrs from 0)
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 scanscan (
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 scanscan (
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 metadatafield (
ndarray) – Staggered data as a H x W numpy array
- Return type:
ndarray- Returns:
Destaggered data as a H x W numpy array
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