Implementation of a general RANdom SAmple Consensus algorithm. More...
#include <Ransac.h>
Public Member Functions | |
int | estimate (PARAMETER *params, int param_c, int support_limit, int max_rounds, MODEL *model) |
Estimates a model from input data parameters. More... | |
Ransac (int min_params, int max_params) | |
Initialize the algorithm. More... | |
int | refine (PARAMETER *params, int param_c, int support_limit, int max_rounds, MODEL *model, char *inlier_mask=NULL) |
Iteratively makes the estimated model better. More... | |
virtual | ~Ransac () |
Public Member Functions inherited from alvar::RansacImpl | |
int | estimateRequiredRounds (float success_propability, float inlier_percentage) |
How many rounds are needed for the Ransac to work. More... | |
Protected Member Functions | |
void | _doEstimate (void **params, int param_c, void *model) |
bool | _doSupports (void *param, void *model) |
virtual void | doEstimate (PARAMETER **params, int param_c, MODEL *model)=0 |
Creates a model estimate from a set of parameters. More... | |
virtual bool | doSupports (PARAMETER *param, MODEL *model)=0 |
Computes how well a parameters supports a model. More... | |
Protected Member Functions inherited from alvar::RansacImpl | |
virtual void | _doEstimate (int *params, int param_c, void *model) |
virtual bool | _doSupports (int param, void *model) |
int | _estimate (void *params, int param_c, int support_limit, int max_rounds, void *model) |
int | _estimate (int param_c, int support_limit, int max_rounds, void *model) |
int | _refine (void *params, int param_c, int support_limit, int max_rounds, void *model, char *inlier_mask=NULL) |
int | _refine (int param_c, int support_limit, int max_rounds, void *model, char *inlier_mask=NULL) |
RansacImpl (int min_params, int max_params, int sizeof_param, int sizeof_model) | |
RansacImpl (int min_params, int max_params, int sizeof_model) | |
virtual | ~RansacImpl () |
Additional Inherited Members | |
Protected Attributes inherited from alvar::RansacImpl | |
void * | hypothesis |
int * | indices |
int | max_params |
int | min_params |
void ** | samples |
int | sizeof_model |
int | sizeof_param |
Implementation of a general RANdom SAmple Consensus algorithm.
This implementation can be used to estimate model from a set of input data. The user needs to provide support methods to compute the best model given a set of input data and to classify input data into inliers and outliers.
For more information see "Martin A Fischler and Robrt C. Bolles: Random Sample Consensus: a paradigm for model fitting with applications to image analysis and automated cartography. Comm of the ACM 24: 381-395" (http://portal.acm.org/citation.cfm?doid=358669.358692).
MODEL is the estimated model, for example endpoints of a line for line fitting.
PARAMETER is the input for model estimation, for example 2D point for line fitting.
MODEL must support an assigment operator.
The user needs to extend this class and provide two methods:
Example: Fitting points to a line:
|
inline |
Initialize the algorithm.
Uses at least min_params and at most max_params number of input data elements for model estimation.
Must be: max_params >= min_params
min_params | is the minimum number of parameters needed to create a model. |
max_params | is the maximum number of parameters to using in refining the model. |
|
inlinevirtual |
|
inlineprotectedvirtual |
Wrapper for templated parameters.
Reimplemented from alvar::RansacImpl.
|
inlineprotectedvirtual |
Wrapper for templated parameters.
Reimplemented from alvar::RansacImpl.
|
protectedpure virtual |
Creates a model estimate from a set of parameters.
The user must implement this method to compute model parameters from the input data.
params | An array of pointers to sampled parameters (input data). |
param_c | The number of parameter pointers in the params array. |
model | Pointer to the model where to store the estimate. |
|
protectedpure virtual |
Computes how well a parameters supports a model.
This method is used by the RANSAC algorithm to count how many parameters support the estimated model (inliers). Althought this is case specific, usually parameter supports the model when the distance from model prediction is not too far away from the parameter.
param | Pointer to the parameter to check. |
model | Pointer to the model to check the parameter against. |
|
inline |
Estimates a model from input data parameters.
Randomly samples min_params number of input data elements from params array and chooses the model that has the largest set of supporting parameters (inliers) in the params array.
Note that this method always uses min_params number of parameters, that is, doEstimate method can be implemented to support only the minimum number of parameters unless refine method is used.
params | Parameters that the model is estimated from (input data). |
param_c | Number of elements in the params array. |
support_limit | The search is stopped if a model receives more support that this limit. |
max_rounds | How many different samples are tried before stopping the search. |
model | The estimated model is stored here. |
|
inline |
Iteratively makes the estimated model better.
Starting with the estimated model, computes the model from all inlier parameters and interates until no new parameters support the model.
Note that this method uses up to max_params number of parameters, that is, doEstimate method must be implemented in such a way that it can estimate a model from a variable number of parameters.
params | Parameters that the model is estimated from. |
param_c | Number of parameters. |
support_limit | The search is stopped is a model receives more support that this limit. |
max_rounds | How many iterations of the refinement are run. |
model | The estimated model that is refined. |
inlier_mask | Byte array where 1 is stored for inliers and 0 for outliers. |