Recording, Streaming, and Conversion

Recording Sensor Data

It’s easy to record data to a pcap file from a sensor programatically. Let’s try it on a configured sensor:

$ python3 -m ouster.sdk.examples.client $SENSOR_HOSTNAME record-pcap

This will capture the client.LidarPacket’s and client.ImuPacket’s data for 10 seconds and store the pcap file along with the metadata json file into the current directory.

The source code of an example below:

 1from more_itertools import time_limited
 2# connect to sensor and record lidar/imu packets
 3with closing(client.Sensor(hostname, lidar_port, imu_port,
 4                           buf_size=640)) as source:
 6    # make a descriptive filename for metadata/pcap files
 7    time_part ="%Y%m%d_%H%M%S")
 8    meta = source.metadata
 9    fname_base = f"{meta.prod_line}_{}_{meta.mode}_{time_part}"
11    print(f"Saving sensor metadata to: {fname_base}.json")
12    source.write_metadata(f"{fname_base}.json")
14    print(f"Writing to: {fname_base}.pcap (Ctrl-C to stop early)")
15    source_it = time_limited(n_seconds, source)
16    n_packets = pcap.record(source_it, f"{fname_base}.pcap")
18    print(f"Captured {n_packets} packets")

Good! The resulting pcap and json files can be used with any examples in the examples.pcap module.

Streaming Live Data

Instead of working with a recorded dataset or a few captured frames of data, let’s see if we can get a live feed from your configured sensor:

$ python3 -m ouster.sdk.examples.client $SENSOR_HOSTNAME live-plot-signal

This should give you a live feed from your sensor that looks like a black and white moving image. Try waving your hand or moving around to find yourself within the image!

So how did we do that?

 1# establish sensor connection
 2with closing(, lidar_port,
 3                                 complete=False)) as stream:
 4    show = True
 5    while show:
 6        for scan in stream:
 7            # uncomment if you'd like to see frame id printed
 8            # print("frame id: {} ".format(scan.frame_id))
 9            signal = client.destagger(stream.metadata,
10                                      scan.field(client.ChanField.SIGNAL))
11            signal = (signal / np.max(signal) * 255).astype(np.uint8)
12            cv2.imshow("scaled signal", signal)
13            key = cv2.waitKey(1) & 0xFF

Notice that instead of taking a sample, we used, which allows for a continuous live data stream. We close the stream when we are finished, hence the use of closing() in the highlighted line.

To exit the visualization, you can use ESC.