Contenido principal

extractFrame

Extract point cloud frame

Since R2025a

Description

[ptCloudExtracted,tform] = extractFrame(pcExtractor) extracts the next available point cloud ptCloudExtracted from the input point cloud extractor object pcExtractor. The syntax also returns a 3D rigid geometric transformation object, tform, which you can use to transform the extracted point cloud frames from the local coordinate system to the point cloud map coordinate system.

[ptCloudExtracted,tform] = extractFrame(pcExtractor,frameIndex) extracts and returns the point cloud ptCloudExtracted for the specified index frameIndex of the input point cloud extractor object pcExtractor.

Note

This function requires the Scenario Builder for Automated Driving Toolbox™ support package and Lidar Toolbox™. 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

Examples

collapse all

Load recorded point cloud data into the workspace.

ptCloud = pcread("USGS_LPC_CA_NoCAL_3DEP_Supp_Funding_2018_D18_w2276n1958_Cropped_geoReferenced.pcd");

Display the point cloud object.

pcshow(ptCloud)

Specify the xyz-coordinates of waypoints to create a trajectory. The trajectory coordinates must be within the spatial range of the loaded point cloud data.

egoTraj = [-122.8437 12.1113 39.8113;
            -21.3297 32.1351 33.9599;
             80.4809 49.1138 32.9193];

Specify timestamps for the waypoints of the trajectory.

timestamps = (1:3)'; 

Create a trajectory object by using the specified xyz-coordinates and timestamps.

traj = recordedSensorData("trajectory",timestamps,egoTraj);

Plot the trajectory object.

plot(traj,HeadingStep=1,ShowHeading=true)

Create an ego point cloud extractor object using the point cloud and trajectory information.

pcExtractor = egoPointCloudExtractor(ptCloud,traj)
pcExtractor = 
  egoPointCloudExtractor with properties:

              Height: 1.6000
            MaxRange: 120
    SensorParameters: []
          PointCloud: [1×1 pointCloud]
          Trajectory: [1×1 scenariobuilder.Trajectory]
      NumPointClouds: 3

Extract and display point cloud frames from the ego point cloud extractor object until it has no new frames to extract.

figure
frame = 0;
while(hasFrame(pcExtractor))
    pcFrame = extractFrame(pcExtractor);
    frame = frame + 1;
    subplot(1,3,frame)
    pcshow(pcFrame)
end

Reset the ego point cloud extractor object.

reset(pcExtractor)

Load recorded point cloud data into the workspace.

ptCloud = pcread("USGS_LPC_CA_NoCAL_3DEP_Supp_Funding_2018_D18_w2276n1958_Cropped_geoReferenced.pcd");

Specify the xyz-coordinates of waypoints to create a trajectory. The trajectory coordinates must be within the spatial range of the loaded point cloud data.

egoTraj = [-122.8437 12.1113 39.8113;
            -21.3297 32.1351 33.9599;
             80.4809 49.1138 32.9193];

Specify timestamps for the waypoints of the trajectory.

timestamps = (1:3)';

Create a trajectory object by using the specified xyz-coordinates and timestamps.

traj = recordedSensorData("trajectory",timestamps,egoTraj);

Create an ego point cloud extractor object using the point cloud and trajectory information.

pcExtractor = egoPointCloudExtractor(ptCloud,traj);

Initialize an empty point cloud array and a 3D rigid geometric transformation object.

pcFrameArray = pointCloud(zeros(0,pcExtractor.NumPointClouds));
tformArray = rigidtform3d;

Extract all point cloud frames and 3D rigid geometric transformation objects from the ego point cloud extractor object.

for i = 1:pcExtractor.NumPointClouds
   [pcFrameArray(i),tformArray(i)] = extractFrame(pcExtractor,i);
end

Extracted point cloud frames are in the vehicle coordinate system. Transform the extracted point cloud frames from the vehicle coordinate system to the point cloud map coordinate system by using the pcalign function. The function aligns the extracted array of point clouds into one point cloud using the extracted geometric transformation information.

pcAligned = pcalign(pcFrameArray,tformArray);

Display the transformed point cloud.

pcshow(pcAligned)

Input Arguments

collapse all

Ego point cloud extractor, specified as an egoPointCloudExtractor object.

Index of the point cloud frame to extract from the input point cloud extractor object, specified as a positive integer.

The value of frameIndex is relative to the NumPointClouds property of the input point cloud extractor object pcExtractor. The maximum value of frameIndex is the value of the NumPointClouds property of the input point cloud extractor object pcExtractor.

Data Types: single | double

Output Arguments

collapse all

Extracted point cloud frame, returned as a pointCloud object.

If the SensorParameters property of the input ego point cloud extractor object pcExtractor contains lidar sensor parameters, the function returns an organized point cloud. For more information, see What Are Organized and Unorganized Point Clouds? (Lidar Toolbox).

3D rigid geometric transformation, returned as a rigidtform3d object.

You can use the returned rigidtform3d object tform to transform the returned point clouds ptCloudExtracted from the local coordinate system to the point cloud map coordinate system.

Version History

Introduced in R2025a