Main Content

pcshowMatchedFeatures

Display point clouds with matched feature points

Description

pcshowMatchedFeatures(ptCloud1,ptCloud2,matchedPtCloud1,matchedPtCloud2) displays point clouds, ptCloud1 and ptCloud2, with their matched feature points, matchedPtCloud1 and matchedPtCloud2. The plot is color coded by point cloud and each connected to the corresponding point in the other point cloud by a line.

example

pcshowMatchedFeatures(segments1,segments2,features1,features2) displays the point cloud segments, segments1 and segments2, with their corresponding centroids in the Centroid property of features1 and features2. The plot is color coded and the corresponding centroids are connected by a line.

ax = pcshowMatchedFeatures(___) additionally returns an Axes object using the input arguments from the previous syntax.

example

[___] = pcshowMatchedFeatures(___,Name,Value) specifies options using one or more name-value pair arguments in addition to any combination of arguments in previous syntaxes. For example, 'Method','montage' visualizes the point clouds next to each other in the axes.

Examples

collapse all

This example shows how to visualize matching point cloud features using the pcshowMatchedFeatures function. The example uses features calculated using extractFPFHFeatures function.

Load the required files into the workspace.

load("features1.mat");
load("features2.mat");
load("ptCloud1.mat");
load("ptCloud2.mat");

Match features between two point clouds.

indexPairs = pcmatchfeatures(features1,features2,ptCloud1,ptCloud2);

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

matchedPts1 = select(ptCloud1,indexPairs(:,1));
matchedPts2 = select(ptCloud2,indexPairs(:,2));

Visualize the matches.

pcshowMatchedFeatures(ptCloud1,ptCloud2,matchedPts1,matchedPts2, ...
    "Method","montage")
xlim([-40 210])
ylim([-50 50])
title("Matched Points")

Figure contains an axes object. The axes object with title Matched Points contains 5 objects of type scatter, line.

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 matched features.

Create a Velodyne PCAP file reader.

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

Read the first and fourth scans from the file.

ptCloud1 = readFrame(veloReader,1);
ptCloud2 = readFrame(veloReader,4);

Remove the ground plane from the scans.

maxDistance = 1; % in meters
referenceVector = [0 0 1];
[~,~,selectIdx] = pcfitplane(ptCloud1,maxDistance,referenceVector);
ptCloud1 = select(ptCloud1,selectIdx,'OutputSize','full');
[~,~,selectIdx] = pcfitplane(ptCloud2,maxDistance,referenceVector);
ptCloud2 = select(ptCloud2,selectIdx,'OutputSize','full');

Cluster the point clouds with a minimum of 10 points per cluster.

minDistance = 2; % in meters
minPoints = 10;
labels1 = pcsegdist(ptCloud1,minDistance,'NumClusterPoints',minPoints);
labels2 = pcsegdist(ptCloud2,minDistance,'NumClusterPoints',minPoints);

Extract eigen-value features and the corresponding segments from each point cloud.

[eigFeatures1,segments1] = extractEigenFeatures(ptCloud1,labels1);
[eigFeatures2,segments2] = extractEigenFeatures(ptCloud2,labels2);

Create matrices of the features and centroids extracted from each point cloud, for matching.

features1 = vertcat(eigFeatures1.Feature);
features2 = vertcat(eigFeatures2.Feature);
centroids1 = vertcat(eigFeatures1.Centroid);
centroids2 = vertcat(eigFeatures2.Centroid);

Find putative feature matches.

indexPairs = pcmatchfeatures(features1,features2, ...
    pointCloud(centroids1),pointCloud(centroids2));

Get the matched segments and features for visualization.

matchedSegments1 = segments1(indexPairs(:,1));
matchedSegments2 = segments2(indexPairs(:,2));
matchedFeatures1 = eigFeatures1(indexPairs(:,1));
matchedFeatures2 = eigFeatures2(indexPairs(:,2));

Visualize the matches.

figure
pcshowMatchedFeatures(matchedSegments1,matchedSegments2,matchedFeatures1,matchedFeatures2)
title('Matched Segments')

Figure contains an axes object. The axes object with title Matched Segments contains 5 objects of type scatter, line.

Input Arguments

collapse all

First point cloud, specified as a pointCloud object.

Second point cloud, specified as a pointCloud object.

Matched points in the first point cloud, specified as a pointCloud object. Each point is a feature match for the point with the corresponding index in matchedPtCloud2.

Matched points in the second point cloud, specified as a pointCloud object. Each point is a feature match for the point with the corresponding index in matchedPtCloud1.

Point cloud segments, specified as a M-element vector of pointCloud objects.

Point cloud segments, specified as a M-element vector of pointCloud objects.

Corresponding centroids in the first segment features, specified as a M-element vector of eigenFeature objects. The Centroid property of each feature in features1 is plotted with a red circle by default.

Corresponding centroids in the second segment features, specified as a M-element vector of eigenFeature objects. The Centroid property of each feature in features2 is plotted with a blue asterisk by default.

Name-Value Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: 'Method','montage' visualizes the point clouds next to each other in the axes.

Display method, specified as the comma-separated pair consisting of 'Method' and one of these options:

  • 'overlay' — Overlay ptCloud2 on ptCloud1.

  • 'montage' — Display ptCloud1 and ptCloud2 next to each other in the same axes.

Data Types: char | string

Line style and color options, specified as the comma-separated pair consisting of 'PlotOptions' and a cell array of character vectors of the form {MarkerStyle1, MarkerStyle2, LineStyle}. MarkerStyle1 specifies the color and marker symbol for the matched points matchedPtCloud1 in the first point cloud ptCloud1. MarkerStyle2 specifies the color and marker symbol for the matched points matchedPtCloud2 in the second point cloud ptCloud2. LineStyle specifies the color and line style of the lines connecting the matched points of the first point cloud to the matched points of the second. For more information on line styles, marker symbols, and colors, see LineSpec.

Data Types: char

Output axes, specified as the comma-separated pair consisting of 'Parent' and an axes graphics object.

Output Arguments

collapse all

Axes handle, returned as an axes graphics object.

Introduced in R2020b