match and visualize corresponding features in point clouds -凯发k8网页登录
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