Main Content

pcviewset

Manage data for point cloud based visual odometry and SLAM

Description

The pcviewset object stores point cloud odometry and simultaneous localization and mapping (SLAM) data as a set of views and pairwise connections between views.

Creation

Description

example

vSet = pcviewset creates a pcviewset object with default property names. Use object functions to perform actions such as adding, modifying, or removing views or connections.

Properties

expand all

This property is read-only.

View attributes, specified as a three-column table. The table contains columns as described in this table.

ColumnDescription
ViewIDView identifier, specified as an integer. View identifiers are unique to a specific view.
AbsolutePoseAbsolute pose of the view, specified as a rigid3d object.
PointCloudPoint cloud, specified as a pointCloud object.

This property is read-only.

Pairwise connections between views, specified as a four-column table. The table contains columns as described in this table. Each row corresponds to one connection.

ColumnDescription
ViewID1View identifier for the first view, specified as a unique integer.
ViewID2View identifier for the second view, specified as a unique integer.
RelativePoseRelative pose of the second view with respect to the first view, specified as a rigid3d object.
InformationMatrixInformation matrix, specified as a 6-by-6 matrix. The information matrix represents the uncertainty of the measurement error and is the inverse of the covariance matrix.

This property is read-only.

Number of views, specified as a nonnegative integer.

This property is read-only.

Number of connections, specified as a nonnegative integer.

Object Functions

addViewAdd views to view set
updateViewUpdate view in view set
deleteViewDelete view from view set
hasViewCheck if view is in view set
addConnectionAdd connection between views in view set
updateConnectionUpdate connection between views in a view set
deleteConnectionDelete a connection between views in view set
hasConnectionCheck if connection between two views is in view set
connectedViewsConnected views in view set
posesAbsolute poses associated with views in view set
createPoseGraphCreate pose graph
optimizePosesOptimize absolute poses using relative pose constraints
plotPlot view set views and connections

Examples

collapse all

Create a view set to hold odometry.

 vSet = pcviewset;

Create a Velodyne reader to read point clouds.

veloReader = velodyneFileReader('lidarData_ConstructionRoad.pcap','HDL32E');
ptCloud = readFrame(veloReader);

Preprocess one frame to remove the ground plane and to downsample point cloud.

elevationDelta = 25;
gridStep       = 0.2;
groundPtsIdx = segmentGroundFromLidarData(ptCloud, ...
    'ElevationAngleDelta',elevationDelta);
ptCloud = select(ptCloud, ~groundPtsIdx,'Output','full');
ptCloud = pcdownsample(ptCloud,'gridAverage',gridStep);

Initialize attributes for the first view.

absPose = rigid3d;
relPose = rigid3d;

Add the first view to the point cloud view set.

vSet = addView(vSet,1,absPose,'PointCloud',ptCloud);

Initialize a point cloud map using the first view.

ptCloudMap = copy(ptCloud);

skipFrames = 5;
prevViewId = 1;
prevPtCloud = ptCloud;

Loop over frames to update odometry and the point cloud map.

for viewId = 6 : skipFrames : 50
    % Read point cloud.
    ptCloud = readFrame(veloReader,viewId);

    %Preprocess the frame.
    groundPtsIdx = segmentGroundFromLidarData(ptCloud, ...
        'ElevationAngleDelta', elevationDelta);
    ptCloud = select(ptCloud, ~groundPtsIdx, 'Output', 'full');
    ptCloud = pcdownsample(ptCloud, 'gridAverage', gridStep);

    % Register new point cloud against the previous one.
    regGridStep = 5;
    relPose = pcregisterndt(ptCloud, prevPtCloud, regGridStep, ...
        'InitialTransform', relPose);

    % Update the absolute transform.
    absPose = rigid3d( relPose.T*absPose.T );

    % Add new view and connection to the previous view.
    vSet = addView(vSet,viewId,absPose,'PointCloud',ptCloud);
    vSet = addConnection(vSet,prevViewId,viewId,relPose);

    prevPtCloud = ptCloud;
    prevViewId  = viewId;
end

Display the view set in a default 2-D view.

plot(vSet, 'ShowViewIds', 'on')
view(2)

Introduced in R2020a