1. RANSAC algorithm
MRPT comprises a generic C++ implementation of this robust model fit algorithm.
For a theoretical description of the algorithm, refer to this Wikipedia article and the cites herein.
See also the excellent MATLAB toolkit by Kovesi, on which MRPT's implementation is strongly based.
Note: In MRPT 0.9.4 a new RANSAC implementation was introduced which can be used to fit a model using both RANSAC and a simple genetic-like modification of RANSAC. Refer to the template class mrpt::math::ModelSearch.
2. C++ Examples
A few sample applications of RANSAC are provided with MRPT. The generic implementation can be found in the class mrpt::math::RANSAC_template, whose main method is:
01 |
static bool mrpt::math::RANSAC_Template< NUMTYPE >::execute ( |
02 |
const CMatrixTemplateNumeric< NUMTYPE > & data, |
03 |
TRansacFitFunctor fit_func, |
04 |
TRansacDistanceFunctor dist_func, |
05 |
TRansacDegenerateFunctor degen_func, |
06 |
const double distanceThreshold, |
07 |
const unsigned int minimumSizeSamplesToFit, |
08 |
mrpt::vector_size_t & out_best_inliers, |
09 |
CMatrixTemplateNumeric< NUMTYPE > & out_best_model, |
10 |
bool verbose = false , |
11 |
const double prob_good_sample = 0.999, |
12 |
const size_t maxIter = 2000 |
13 |
) |
For the complete documentation of this class, please see mrpt::math::RANSAC_Template<>.
A complete example of how to use this templatized version can be found in: http://mrpt.googlecode.com/svn/trunk/samples/ransac-demo-plane3D/
There exist as well other application-specific methods (like the N-planes detector), which instantiate the generic template to offer a more user-friendly interface for each specific problem. See mrpt::math::ransac_detect_3D_planes and the "RANSAC detectors" module, part of the library mrpt-base.
2.1 Fit a 3D plane
The source for this example can be found in: http://mrpt.googlecode.com/svn/trunk/samples/ransac-demo-plane3D
This is the resulting fit plane. Average execution time for 300 inliers and 100 outliers is 0.5 milliseconds on a Pentium M @ 2.0Ghz.
2.2 Fit a number of 3D planes
The source for this example can be found in http://mrpt.googlecode.com/svn/trunk/samples/ransac-demo-applications.
The method tries to identify an unknown number of planes in a point cloud, given a threshold for considering a point as an inlier and a minimum number of inliers to consider a plane hypothesis as valid. Average execution time for 3 planes x 300 inliers and 300 outliers is 60ms on a Pentium M @ 2.0Ghz.
2.3 Fit a number of 2D lines
The source for this example can be found in http://mrpt.googlecode.com/svn/trunk/samples/ransac-demo-applications.
These are the resulting fit lines.
2.4. Data association with RANSAC
See: Example:ransac-data-association.