Main Content


Detect loop closures using scan context descriptors

Since R2021b


scanContextLoopDetector detects loop closures in point cloud data using global scan context descriptors. A scan context descriptor encodes a point cloud view into a 2-D descriptor. scanContextLoopDetector stores the descriptors with a corresponding view identifier to associate the detected loop closures to a view in a pcviewset for map building.




loopDetector = scanContextLoopDetector() creates a default scanContextLoopDetector object. Use the addDescriptor object function to add descriptors to the loop detector. Use the detectLoop object function to detect loop closures.


expand all

This property is read-only.

View identifiers, specified as a P-element vector of unique positive integers, where P is the number of descriptors added to the detector.

This property is read-only.

Scan context descriptors, specified as an M-by-N-by-P array. M is the number of radial bins and N is the number of azimuthal bins in the descriptor. P is the number of descriptors in the detector.

Object Functions

addDescriptorAdd descriptor to the loop closure detector
deleteDescriptorDelete descriptors from the loop closure detector
detectLoopDetect loop closures


collapse all

Create a loop closure detector.

loopDetector = scanContextLoopDetector;

Create a Velodyne PCAP file reader.

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

Read the point clouds and extract the scan context descriptor from each point cloud scan. Add the descriptors to the detector.

for viewId = 1:10
    ptCloud = readFrame(veloReader,viewId);
    descriptor = scanContextDescriptor(ptCloud);

Check if the next point cloud can be classified as a loop closure detection without excluding any recently added descriptors.

viewId = viewId + 1;
ptCloud = readFrame(veloReader,viewId);
descriptor = scanContextDescriptor(ptCloud);
[loopViewId,dists] = detectLoop(loopDetector,descriptor,'NumExcludedDescriptors',0)
loopViewId = uint32
dists = single

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Version History

Introduced in R2021b