Main Content

Match and Visualize Corresponding Features in Point Clouds

This example shows how to match corresponding features between point clouds using the pcmatchfeatures function and visualize them using the pcshowMatchedFeatures function.

Create a velodyneFileReader object.

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

Read two point clouds from the velodyneFileReader object by using the readFrame method.

frameNumber = 1;
skipFrame = 5;
fixed = readFrame(veloReader,frameNumber);
moving = readFrame(veloReader,frameNumber+skipFrame);

Segment and remove the ground plane from the fixed point cloud and moving point cloud.

groundPtsIdxFixed = segmentGroundSMRF(fixed);
groundPtsIdxMoving = segmentGroundSMRF(moving);
fixedSeg = select(fixed,~groundPtsIdxFixed,'OutputSize','full');
movingSeg = select(moving,~groundPtsIdxMoving,'OutputSize','full');
figure
pcshowpair(movingSeg,fixedSeg)
ylim([-50 60])
title('Input Point Clouds')

The superimposed input point clouds are color coded:

  • Magenta Moving point cloud

  • Green Fixed point cloud

Downsample the point clouds to reduce the computation time. Downsampling reduces the number of points to process.

fixedDownsampled = pcdownsample(fixedSeg,'gridAverage',0.2);
movingDownsampled = pcdownsample(movingSeg,'gridAverage',0.2);

Extract features from the point clouds using the extractFPFHFeatures function. The functions returns valid indices in both the point clouds. Select the valid points and create new reference point clouds.

[fixedFeature,fixedValidInds] = extractFPFHFeatures(fixedDownsampled);
[movingFeature,movingValidInds] = extractFPFHFeatures(movingDownsampled);
fixedValidPts = select(fixedDownsampled,fixedValidInds);
movingValidPts = select(movingDownsampled,movingValidInds);

Match features between the point clouds using the extracted features and reference point clouds.

indexPairs = pcmatchfeatures(movingFeature,fixedFeature,movingValidPts, ...
    fixedValidPts);

If you do not have the corresponding point cloud data, you can use the two feature sets by themselves. The pcmatchfeatures function uses point cloud data to estimate the spatial relation between the points associated with potential feature matches and reject matches based on a spatial relation threshold.

Create point clouds of only the points in each point cloud with matching features in the other point cloud.

matchedFixedPts = select(fixedValidPts,indexPairs(:,2));
matchedMovingPts = select(movingValidPts,indexPairs(:,1));

Visualize the matches.

figure
pcshowMatchedFeatures(movingSeg,fixedSeg,matchedMovingPts,matchedFixedPts, ...
    'Method','montage')
xlim([-40 210])
ylim([-50 50])
title('Matched Points')

The matched features and point clouds are color coded to improve visualization:

  • Magenta Moving point cloud

  • Green Fixed point cloud

  • Red circle Matched points in the moving point cloud

  • Blue asterisk Matched points in the fixed point cloud

  • Yellow Line connecting the matched features