You are here

RANSAC C++ examples

 

 

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:

static bool mrpt::math::RANSAC_Template< NUMTYPE >::execute (
    const CMatrixTemplateNumeric< NUMTYPE > & data,
    TRansacFitFunctor                         fit_func,
    TRansacDistanceFunctor                    dist_func,
    TRansacDegenerateFunctor                  degen_func,
    const double                              distanceThreshold,
    const unsigned int                        minimumSizeSamplesToFit,
    mrpt::vector_size_t                     & out_best_inliers,
    CMatrixTemplateNumeric< NUMTYPE >       & out_best_model,
    bool                                      verbose = false,
    const double                              prob_good_sample = 0.999,
    const size_t                              maxIter = 2000
    ) 

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.

ransac data-association

 

Tags: