Recording, Streaming, and Conversion

To work with your sensor, you should configure the ports. See set-configuration for more details.

Each config parameter corresponds directly to the sensor configuration parameters available on the sensor.

You can run the above code, captured in the configure_sensor_params() example, as follows:

$ python3 -m ouster.sdk.examples.core $SENSOR_HOSTNAME configure-sensor
PS > py -3 -m ouster.sdk.examples.core $SENSOR_HOSTNAME configure-sensor

Once you’ve configured your sensor, you shouldn’t have to configure it again until it shuts down or restarts. You can explore the persist flag to persist port and udp_dest settings over sensor restarts.

Recording Sensor Data

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

$ python3 -m ouster.sdk.examples.core $SENSOR_HOSTNAME record-pcap
PS >  py -3 -m ouster.sdk.examples.core $SENSOR_HOSTNAME record-pcap

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

Note

TODO: Link to pcap write to file in MR 2

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.core $SENSOR_HOSTNAME live-plot-reflectivity
PS > py -3 -m ouster.sdk.examples.core $SENSOR_HOSTNAME live-plot-reflectivity

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?

# establish sensor connection via open_source
from ouster.sdk import open_source
with closing(open_source(hostname,
                         collate=False,
                         sensor_idx=0,
                         lidar_port=lidar_port)) as stream:
    show = True
    while show:
        for frames in stream:
            frame = frames[0]
            if frame is None:
                continue
            # uncomment if you'd like to see frame id printed
            # print("frame id: {} ".format(frame.frame_id))
            reflectivity = core.destagger(stream.sensor_info[0],
                                          frame.field(core.ChanField.REFLECTIVITY))
            reflectivity = (reflectivity / np.max(reflectivity) * 255).astype(np.uint8)
            cv2.imshow("scaled reflectivity", reflectivity)
            key = cv2.waitKey(1) & 0xFF

To exit the visualization, you can use ESC.