Main Content

LidarData

Store sequence of lidar data with timestamps

Since R2024b

Description

The LidarData object stores a sequence of lidar point cloud data.

Creation

Description

lidarData = scenariobuilder.LidarData creates an empty LidarData object, lidarData.

lidarData = scenariobuilder.LidarData(timestamps,pointClouds) creates a LidarData object, lidarData, with the Timestamps and PointClouds properties set by the timestamps and pointClouds arguments, respectively. Additionally, this syntax sets the SampleRate, SampleTime, TimeDuration, and NumSamples properties.

lidarData = scenariobuilder.LidarData(rosbag,topic) extracts data such as timestamps and point cloud data from the specified topic topic in the input rosbag file rosbag, and creates a LidarData object, lidarData. (since R2025b)

Note: To use a rosbag file or ROS 2 bag file, you must have a ROS Toolbox license.

example

lidarData = scenariobuilder.LidarData(timestamps,pointClouds,Name=Value) sets writable properties using one or more name-value arguments. For example, Name="lidar1" specifies the name of the lidar sensor as "lidar1".

Note

This feature requires the Scenario Builder for Automated Driving Toolbox™ support package. You can install the Scenario Builder for Automated Driving Toolbox support package from the Add-On Explorer. For more information about installing add-ons, see Get and Manage Add-Ons.

example

Input Arguments

expand all

Timestamps of the lidar data, specified as an N-element numeric column vector, an N-element datetime array, or an N-element duration array. N is the number of timestamps. Each element in the timestamps argument specifies the time at which the corresponding lidar data was collected. If you specify an N-element numeric column vector, units must be in seconds.

This argument sets the Timestamps property.

Lidar point cloud data, specified as an N-by-1 array of pointCloud objects, N-by-1 string array, N-by-1 cell array of character vectors, or a string scalar. N is the number of timestamps.

If you specify an N-by-1 string array or an N-by-1 cell array of character vectors, each element in the array represents a point cloud filename, an absolute or relative path of a point cloud file. The point cloud file must be of PLY or PCD format.

If you specify a string scalar, the string must specify an absolute or relative path to a folder containing point cloud files.

This argument sets the PointClouds property.

Since R2025b

Rosbag filename, specified as a string scalar, character vector, BagSelection (ROS Toolbox) object, or ros2bagreader (ROS Toolbox) object.

If you specify a string scalar or character vector, the rosbag argument must represent an absolute or relative path to a rosbag file with the .bag extension or a ROS 2 bag file with the .db3 extension. For example, if the file myFile.bag is in your current folder, C:\myFolder, you can specify rosbag as "myFile.bag" or "C:\myFolder\myFile.bag".

Since R2025b

Topic name in the input rosbag file, specified as a string scalar or character vector.

The value of this argument must correspond to the name of a topic in the specified rosbag file rosbag. To find all topic names in the rosbag file, use the rosbag('info',filename) syntax of the rosbag (ROS Toolbox) function.

Data Types: char | string

Name-Value Arguments

expand all

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Example: scenariobuilder.LidarData(Name="lidar1") specifies the name of the lidar sensor as "lidar1".

Name of the lidar sensor, specified as a string scalar or character vector.

This argument sets the Name property.

Data Types: char | string

Optional lidar sensor parameters, specified as lidar parameters specifying sensor characteristics, mounting information, or transformations, such as a rigidtform3d object.

This argument sets the SensorParameters property.

Optional lidar attributes, specified as an N-by-1 array. N is the number of timestamps. Each element in the array contains the additional lidar attributes, such as classification labels, detected at the corresponding timestamp.

This argument sets the Attributes property.

Properties

expand all

Name of the lidar sensor, specified as a string scalar or character vector.

Data Types: char | string

This property is read-only.

Number of point cloud samples, represented as a nonnegative integer.

Data Types: uint8 | uint16 | uint32 | uint64

This property is read-only.

Time duration for which the lidar data was acquired, represented as a nonnegative scalar. Units are in seconds.

Data Types: double

This property is read-only.

Mean sample rate of the lidar data, represented as a nonnegative scalar. This value defines the number of point cloud frames per second. Units are in hertz.

Data Types: double

This property is read-only.

Mean sample time of the lidar data, represented as a nonnegative scalar. This value defines the mean time interval between two consecutive point cloud frames. Units are in seconds.

Data Types: double

This property is read-only after object creation. To set this property, use the timestamps argument when calling the scenarioBuilder.LidarData function.

Timestamps of the lidar data, represented as an N-element numeric column vector, an N-element datetime array, or an N-element duration array. N is the number of timestamps. Each element in the Timestamps property specifies the time at which the corresponding lidar data was collected. If you specify an N-element numeric column vector, units must be in seconds.

When you initialize the object with timestamps and pointClouds, the object arranges the data by the input timestamps in increasing order.

This property is read-only after object creation. To set this property, use the pointClouds argument when calling the scenarioBuilder.LidarData function.

Lidar point cloud data, represented as an N-by-1 cell array. N is the number of timestamps. Each cell is a string scalar, character vector, or a pointCloud object. If represented as a string scalar or a character vector, it specifies a point cloud filename, or an absolute or a relative path of a point cloud file.

Optional lidar sensor parameters, specified as lidar parameters specifying sensor characteristics, mounting information, or transformations, such as a rigidtform3d object.

Optional lidar attributes, specified as an N-by-1 array. N is the number of timestamps. Each element in the array contains the additional lidar attributes, such as classification labels, detected at the corresponding timestamp.

Object Functions

addAdd data to lidar data object
removeRemove data from sensor data object
readRead data from sensor data object
copyCreate copy of sensor data object
cropCrop data from sensor data object
synchronizeSynchronize sensor data with reference sensor information
playPlay point clouds from lidar data object
datastoreCreate datastore from sensor data object
normalizeTimestampsNormalize timestamps of sensor data object
convertTimestampsConvert timestamp format of sensor data object

Examples

collapse all

Specify a path containing a sequence of point cloud files.

files = dir(fullfile(toolboxdir("vision"),"visiondata","pcdmapseq","*.pcd"));
pcds = strcat({files.folder},filesep,{files.name})';

Specify timestamps for each point cloud in the point cloud data.

timestamps = (1:4)';

Create an empty lidar data object.

lidarData = scenariobuilder.LidarData(Name="LidarSensor")
lidarData = 
  LidarData with properties:

                Name: "LidarSensor"

          NumSamples: 0
            Duration: 0
          SampleRate: 0
          SampleTime: 0
          Timestamps: []

         PointClouds: []
    SensorParameters: []

          Attributes: []

Add your data samples to the lidar data object.

add(lidarData,timestamps,pcds)

Visualize the lidar data object.

play(lidarData)

Since R2025b

Create a camera data object and a lidar data object from a rosbag file.

Note: This example requires a ROS Toolbox license.

Download a ZIP file, DrivingData_Seg7_Seq30.zip, and then unzip the file. The file contains raw sensor data, such as GPS data, camera data, and lidar data. The rosbag file MultiSensorDrivingData_Seg7_Seq30.bag contains 100 frames of raw camera data and 60 frames of raw lidar data.

dataFolder = pwd;
dataFilename = "DrivingData_Seg7_Seq30.zip";
url = "https://ssd.mathworks.com/supportfiles/driving/data/" + dataFilename;
filePath = fullfile(dataFolder,dataFilename);
if ~isfile(filePath)
    websave(filePath,url);
end
unzip(filePath,dataFolder)
rosFilePath = fullfile(dataFolder,"DrivingData_Seg7_Seq30","MultiSensorDrivingData_Seg7_Seq30.bag");

Create a camera data object from the rosbag file.

camData = scenariobuilder.CameraData(rosFilePath,"/flir_adk_out/camera_21355709/image_raw")
camData = 
  CameraData with properties:

                Name: ''

          NumSamples: 100
            Duration: 14.5894
          SampleRate: 6.8543
          SampleTime: 0.1474
          Timestamps: [100×1 double]

              Frames: [100×1 string]
    SensorParameters: []

          Attributes: []

Visualize the camera data object.

play(camData)

Create a lidar data object from the rosbag file.

lidarData = scenariobuilder.LidarData(rosFilePath,"/os1_cloud_node/points")
lidarData = 
  LidarData with properties:

                Name: ''

          NumSamples: 60
            Duration: 14.7427
          SampleRate: 4.0698
          SampleTime: 0.2499
          Timestamps: [60×1 double]

         PointClouds: [60×1 string]
    SensorParameters: []

          Attributes: []

Visualize the lidar data object.

play(lidarData)

Version History

Introduced in R2024b

expand all