OpenGV
A library for solving calibrated central and non-central geometric vision problems
opengv::sac::SampleConsensusProblem< MODEL_T > Class Template Referenceabstract

#include <SampleConsensusProblem.hpp>

Public Types

typedef MODEL_T model_t
 

Public Member Functions

 SampleConsensusProblem (bool randomSeed=true)
 Contructor. More...
 
virtual ~SampleConsensusProblem ()
 Destructor.
 
virtual void getSamples (int &iterations, std::vector< int > &samples)
 Get samples for hypothesis generation. More...
 
virtual bool isSampleGood (const std::vector< int > &sample) const
 Check if a set of samples for model generation is degenerate. More...
 
std::shared_ptr< std::vector< int > > getIndices () const
 Get a pointer to the vector of indices used. More...
 
void drawIndexSample (std::vector< int > &sample)
 Sub-function for getting samples for hypothesis generation. More...
 
virtual int getSampleSize () const =0
 Get the number of samples needed for a hypothesis generation. Needs implementation in the child class. More...
 
virtual bool computeModelCoefficients (const std::vector< int > &indices, model_t &outModel) const =0
 Compute a model from a set of samples. Needs implementation in the child-class. More...
 
virtual void optimizeModelCoefficients (const std::vector< int > &inliers, const model_t &model_coefficients, model_t &optimized_coefficients)=0
 Refine the model coefficients over a given set (inliers). Needs implementation in the child-class. More...
 
virtual void getSelectedDistancesToModel (const model_t &model, const std::vector< int > &indices, std::vector< double > &scores) const =0
 Compute the distances of all samples whith respect to given model coefficients. Needs implementation in the child-class. More...
 
virtual void getDistancesToModel (const model_t &model_coefficients, std::vector< double > &distances)
 Compute the distances of all samples which respect to given model coefficients. More...
 
virtual void selectWithinDistance (const model_t &model_coefficients, const double threshold, std::vector< int > &inliers)
 Select all the inlier samples whith respect to given model coefficients. More...
 
virtual int countWithinDistance (const model_t &model_coefficients, const double threshold)
 Count all the inlier samples whith respect to given model coefficients. More...
 
void setIndices (const std::vector< int > &indices)
 Set the indices_ variable (see member-description). More...
 
void setUniformIndices (int N)
 Use this method if you want to use all samples. More...
 
int rnd ()
 Get a random number. More...
 

Public Attributes

int max_sample_checks_
 
std::shared_ptr< std::vector< int > > indices_
 
std::vector< int > shuffled_indices_
 
std::mt19937 rng_alg_
 std-based random number generator algorithm.
 
std::shared_ptr< std::uniform_int_distribution<> > rng_dist_
 std-based random number generator distribution.
 
std::shared_ptr< std::function< int()> > rng_gen_
 std-based random number generator.
 

Detailed Description

template<typename MODEL_T>
class opengv::sac::SampleConsensusProblem< MODEL_T >

Basis-class for Sample-consensus problems containing the three basic functions for model-fitting.

Member Typedef Documentation

template<typename MODEL_T>
typedef MODEL_T opengv::sac::SampleConsensusProblem< MODEL_T >::model_t

The model we are trying to fit

Constructor & Destructor Documentation

template<typename MODEL_T>
opengv::sac::SampleConsensusProblem< MODEL_T >::SampleConsensusProblem ( bool  randomSeed = true)

Contructor.

Parameters
[in]randomSeedSetting the seed of the random number generator with something unique, namely the current time.

Member Function Documentation

template<typename MODEL_T>
virtual bool opengv::sac::SampleConsensusProblem< MODEL_T >::computeModelCoefficients ( const std::vector< int > &  indices,
model_t outModel 
) const
pure virtual
template<typename MODEL_T>
virtual int opengv::sac::SampleConsensusProblem< MODEL_T >::countWithinDistance ( const model_t model_coefficients,
const double  threshold 
)
virtual

Count all the inlier samples whith respect to given model coefficients.

Parameters
[in]model_coefficientsThe coefficients of the model hypothesis.
[in]thresholdA maximum admissible distance threshold for determining the inliers and outliers.
Returns
The resultant number of inliers
template<typename MODEL_T>
void opengv::sac::SampleConsensusProblem< MODEL_T >::drawIndexSample ( std::vector< int > &  sample)

Sub-function for getting samples for hypothesis generation.

Parameters
[out]sampleThe indices of the samples we attempt to use.
template<typename MODEL_T>
virtual void opengv::sac::SampleConsensusProblem< MODEL_T >::getDistancesToModel ( const model_t model_coefficients,
std::vector< double > &  distances 
)
virtual

Compute the distances of all samples which respect to given model coefficients.

Parameters
[in]model_coefficientsThe coefficients of the model hypothesis.
[out]distancesThe resultant distances of all samples. Low distances mean a good fit.
template<typename MODEL_T>
std::shared_ptr< std::vector<int> > opengv::sac::SampleConsensusProblem< MODEL_T >::getIndices ( ) const

Get a pointer to the vector of indices used.

Returns
A pointer to the vector of indices used.
template<typename MODEL_T>
virtual void opengv::sac::SampleConsensusProblem< MODEL_T >::getSamples ( int &  iterations,
std::vector< int > &  samples 
)
virtual

Get samples for hypothesis generation.

Parameters
[in]iterationsWe won't try forever to get a good sample, this parameter keeps track of the iterations.
[out]samplesThe indices of the samples we attempt to use.
template<typename MODEL_T>
virtual void opengv::sac::SampleConsensusProblem< MODEL_T >::getSelectedDistancesToModel ( const model_t model,
const std::vector< int > &  indices,
std::vector< double > &  scores 
) const
pure virtual

Compute the distances of all samples whith respect to given model coefficients. Needs implementation in the child-class.

Parameters
[in]modelThe coefficients of the model hypothesis.
[in]indicesThe indices of the samples of which we compute distances.
[out]scoresThe resultant distances of the selected samples. Low distances mean a good fit.

Implemented in opengv::sac_problems::relative_pose::NoncentralRelativePoseSacProblem, opengv::sac_problems::absolute_pose::AbsolutePoseSacProblem, opengv::sac_problems::relative_pose::CentralRelativePoseSacProblem, opengv::sac_problems::relative_pose::EigensolverSacProblem, opengv::sac_problems::relative_pose::RotationOnlySacProblem, opengv::sac_problems::relative_pose::TranslationOnlySacProblem, and opengv::sac_problems::point_cloud::PointCloudSacProblem.

template<typename MODEL_T>
virtual bool opengv::sac::SampleConsensusProblem< MODEL_T >::isSampleGood ( const std::vector< int > &  sample) const
virtual

Check if a set of samples for model generation is degenerate.

Parameters
[in]sampleThe indices of the samples we attempt to use for model instantiation.
Returns
Is this set of samples ok?
template<typename MODEL_T>
virtual void opengv::sac::SampleConsensusProblem< MODEL_T >::optimizeModelCoefficients ( const std::vector< int > &  inliers,
const model_t model_coefficients,
model_t optimized_coefficients 
)
pure virtual

Refine the model coefficients over a given set (inliers). Needs implementation in the child-class.

Parameters
[in]inliersThe indices of the inlier samples supporting the model.
[in]model_coefficientsThe initial guess for the model coefficients.
[out]optimized_coefficientsThe resultant refined coefficients.

Implemented in opengv::sac_problems::relative_pose::NoncentralRelativePoseSacProblem, opengv::sac_problems::absolute_pose::AbsolutePoseSacProblem, opengv::sac_problems::relative_pose::CentralRelativePoseSacProblem, opengv::sac_problems::relative_pose::EigensolverSacProblem, opengv::sac_problems::relative_pose::RotationOnlySacProblem, opengv::sac_problems::relative_pose::TranslationOnlySacProblem, and opengv::sac_problems::point_cloud::PointCloudSacProblem.

template<typename MODEL_T>
int opengv::sac::SampleConsensusProblem< MODEL_T >::rnd ( )

Get a random number.

Returns
A random number.
template<typename MODEL_T>
virtual void opengv::sac::SampleConsensusProblem< MODEL_T >::selectWithinDistance ( const model_t model_coefficients,
const double  threshold,
std::vector< int > &  inliers 
)
virtual

Select all the inlier samples whith respect to given model coefficients.

Parameters
[in]model_coefficientsThe coefficients of the model hypothesis.
[in]thresholdA maximum admissible distance threshold for determining the inliers and outliers.
[out]inliersThe resultant indices of inlier samples.
template<typename MODEL_T>
void opengv::sac::SampleConsensusProblem< MODEL_T >::setIndices ( const std::vector< int > &  indices)

Set the indices_ variable (see member-description).

Parameters
[in]indicesThe indices we want to use.
template<typename MODEL_T>
void opengv::sac::SampleConsensusProblem< MODEL_T >::setUniformIndices ( int  N)

Use this method if you want to use all samples.

Parameters
[in]NThe number of samples.

Member Data Documentation

template<typename MODEL_T>
std::shared_ptr< std::vector<int> > opengv::sac::SampleConsensusProblem< MODEL_T >::indices_

The indices of the samples we are using for solving the entire problem. These are not the indices for generating a hypothesis, but all indices for model verification

template<typename MODEL_T>
int opengv::sac::SampleConsensusProblem< MODEL_T >::max_sample_checks_

The maximum number of times we try to extract a valid set of samples

template<typename MODEL_T>
std::vector<int> opengv::sac::SampleConsensusProblem< MODEL_T >::shuffled_indices_

A shuffled version of the indices used for random sample drawing


The documentation for this class was generated from the following file: