Contenuto principale

pcfitcuboid

R2026b

Fit cuboid to 3-D point cloud

Description

model = pcfitcuboid(ptCloud) fits a cuboid over the input point cloud data. The function stores the properties of the cuboid in the cuboidModel object, model.

model = pcfitcuboid(ptCloud,indices) fits a cuboid over a selected set of points, indices, in the input point cloud.

example

Examples

collapse all

Load the point cloud data into the workspace.

ptCloud = load("drivingLidarPoints.mat").ptCloud;

Select a region of interest for cuboid fitting.

roi = [-10 10 -6 8 -2 2];
idx = findPointsInROI(ptCloud,roi);
ptCloudROI = select(ptCloud,idx);

Visualize the cropped point cloud.

figure
pcshow(ptCloudROI)
title("Cropped Point Cloud")

Figure contains an axes object. The axes object with title Cropped Point Cloud contains an object of type scatter.

Segment the ground plane.

maxDistance = 0.5;
[~,idxGround,idxNoGround] = pcfitplane(ptCloudROI,maxDistance);
groundPtCloud = select(ptCloudROI,idxGround);
ptCloudNoGround = select(ptCloudROI,idxNoGround);

Visualize the segmented ground plane.

figure
pcshowpair(groundPtCloud,ptCloudNoGround)
legend("Ground Point Cloud","Non-Ground Point Cloud")
title("Segmented Ground Plane")

Figure contains an axes object. The axes object with title Segmented Ground Plane contains 2 objects of type scatter. These objects represent Ground Point Cloud, Non-Ground Point Cloud.

Segment the non-ground point cloud into clusters.

minDistance = 1;
[labels,numClusters] = pcsegdist(ptCloudNoGround,minDistance);

Visualize the point cloud and each cluster in a different color.

figure
pcshow(ptCloudROI)
hold on
pcshow(ptCloudNoGround.Location,labels)

Fit a cuboid to each cluster, and visualize each cluster with its respective fitted cuboid.

for i = 1:numClusters
    idx = find(labels == i);
    model = pcfitcuboid(ptCloudNoGround,idx);
    plot(model)
end
title("Clustered Point Cloud with Fitted Cuboids")

Figure contains an axes object. The axes object with title Clustered Point Cloud with Fitted Cuboids contains 5 objects of type scatter, patch.

Input Arguments

collapse all

Point cloud, specified as a pointCloud object.

Indices of selected points, specified as a vector of positive integers.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Output Arguments

collapse all

Cuboid model, returned as a cuboidModel object. The function returns an empty cuboid model when the input point cloud contains fewer than four points because at least four points are required to fit a cuboid using a convex-hull based approach.

Algorithms

This algorithm uses the convex hull of the points in the input point cloud to compute an oriented bounding cuboid. The algorithm performs these steps:

  1. Compute the convex hull of the 3-D points.

  2. For each face of the convex hull, compute a candidate cuboid with one face coplanar with the convex hull face.

  3. Select the candidate cuboid with the smallest volume.

When the convex hull contains only a small number of faces, the orientation of the true minimum-volume cuboid might not align with any convex hull face. Because the algorithm considers only orientations derived from convex hull faces, it can return a suboptimal bounding cuboid. For example, four non-coplanar points form a tetrahedral convex hull with only four faces, and the optimal cuboid orientation might not align with any of them.

Version History

Introduced in R2020b

expand all