Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
BIAS::PlaneRANSAC Class Reference

Robust fitting of 3D plane to 3D point set using RANSAC. More...

#include <MathAlgo/Examples/ExampleRANSACPlane.hh>

+ Inheritance diagram for BIAS::PlaneRANSAC:
+ Collaboration diagram for BIAS::PlaneRANSAC:

Public Member Functions

void AddDebugLevel (const long int lv)
 
void AddDebugLevel (const std::string &name)
 
bool DebugLevelIsSet (const long int lv) const
 
bool DebugLevelIsSet (const std::string &name) const
 
virtual bool EvaluateSolution (const HomgPlane3D &solution, bool existing_solution_flag, std::vector< bool > &inlier, int &accept_count, double &evaluate_score, bool &ok_to_terminate_flag)
 The solution denoted by solution needs to be ranked. More...
 
virtual bool GenerateSamples (int sample_index, std::vector< unsigned int > &which_samples)
 pick a set of samples More...
 
bool GenerateSamplesEvenspace (int sample_index, std::vector< unsigned int > &sample_table)
 
bool GenerateSamplesRandom (int sample_index, std::vector< unsigned int > &sampletable)
 
int GetDebugLevel () const
 
std::ostream & GetDebugStream () const
 
void GetDebugStream (std::ostream &os) const
 
double GetFinalScore () const
 
virtual int GetSampleSolutions (std::vector< unsigned int > &which_samples, std::vector< HomgPlane3D > &solutions)
 takes sample and computes solution for this sample. More...
 
void Init (std::vector< HomgPoint3D > &data, double inlier_distance_threshold, bool refine_solution, double expected_inlier_fraction, double solution_error_threshold)
 Initializes RANSAC. More...
 
void Init (unsigned int sample_size, unsigned int max_solutions_per_sample=1, bool refine_solution=false, bool greedy=false)
 
long int Name2DebugLevel (const std::string &name) const
 looks up a debuglevel in the internal map, returns 0 if not found More...
 
long int NewDebugLevel (const std::string &name)
 creates a new debuglevel More...
 
 PlaneRANSAC ()
 
void PrintDebugLevel (std::ostream &os=std::cout) const
 
virtual bool RefineSolution (std::vector< unsigned int > &which_samples, HomgPlane3D &solution, std::vector< bool > &new_inliers)
 RefineSolution is only called, if the RefineSolutionFlag is set to true. More...
 
void RemoveDebugLevel (const long int lv)
 
void RemoveDebugLevel (const std::string &name)
 
void SetDebugLevel (const long int lv)
 
void SetDebugLevel (const std::string &name)
 
void SetDebugStream (const std::ostream &os)
 
void SetMaxSamples (unsigned int max_samples)
 Explicitly set max number of samples. More...
 
void SetSampleCount (unsigned int uiSamples)
 Explicitly set number of samples. More...
 
void ShowDebugLevel (std::ostream &os=std::cout) const
 prints all internally known debuglevels More...
 
virtual int SolveMaster (double inlying_data_fraction, HomgPlane3D &solution, std::vector< bool > &inliers)
 Main computation function called by user. More...
 
 ~PlaneRANSAC ()
 

Static Public Member Functions

static long int GetGlobalDebugLevel ()
 
static void SetGlobalDebugLevel (long int lev)
 

Protected Member Functions

long ConsumeNextFreeDebuglevel_ ()
 returns the next available debuglevel More...
 

Static Protected Member Functions

static int ComputeSampleCount (double inlying_data_fraction, double desired_prob_good, unsigned int sample_size)
 

Protected Attributes

bool _bRefineSolution
 do we want to refine a good sample (one for which evaluate solution returned true)? More...
 
double _dBestInlierEvaluateScore
 
double _dBestSampleEvaluateScore
 
double _dExpectedInlierFraction
 if a sample yields more than _dExpectedInlierFraction inliers and evaluate_score is lower than _dSolutionErrorThreshold, RANSAC will stop More...
 
double _dInlierDistanceThreshold
 3D points with max distance _dInlierDistanceThreshold to plane are considered as inliers More...
 
double _dLastBestSampleEvaluateScore
 
double _dProbabilityOfGoodSolution
 prob. for computing number of samples, set close to 1 More...
 
double _dSolutionErrorThreshold
 if a sample yields more than _dExpectedInlierFraction inliers and evaluate_score is lower than _dSolutionErrorThreshold, RANSAC will stop More...
 
double _dSoSmallSolutionChange
 If all other conditions are right, and the fractional change in the solution statistics is less than this, stop sampling. More...
 
bool _got_solution_flag
 if we already have a solution for which EvaluateSolution returned true More...
 
bool _greedy
 if true, the first acceptable solution is returned More...
 
int _iBestInlierAcceptCount
 refined best values More...
 
int _iBestSampleAcceptCount
 sampled best values More...
 
long int _liDebugLevel
 
long int _liNextDebugLevel
 new concept, debuglevel are managed here in the debug class More...
 
std::map< std::string, long int > _String2Debuglevel
 
unsigned _uiDataSize
 number of data elements needed to compute a solution More...
 
unsigned int _uiExplicitSampleNo
 use this number of samples More...
 
unsigned int _uiMaxSamples
 absolute max number of samples More...
 
unsigned _uiMaxSolutionsPerSample
 max number of solutions that are to be computed for one sample set More...
 
unsigned _uiSampleSize
 number of samples available More...
 
std::vector< HomgPoint3D_vData
 input 3D points to fit 3D plane to More...
 

Static Protected Attributes

static std::ostream _zDebugStream
 
static long int GlobalDebugLevel = 0
 

Detailed Description

Robust fitting of 3D plane to 3D point set using RANSAC.

This class implements an example for RANSAC class overloading.

Method PlaneRANSAC::GetSampleSolutions picks three 3D points and computes a 3D plane from them.

Method PlaneRANSAC::EvaluateSolution evaluates how many points are considered as "inliers" with respect to the computed plane, i.e. their distance to the plane does not exceed a certain threshold.

In PlaneRANSAC::RefineSolution, a linear least squares computation of the plane is done using all inliers to refine the plane parameters.

You have to set the inlier threshold (max. distance to plane to accept a point as being on the plane) and the fraction of valid 3D points which defines the number of samples performed by RANSAC.

When you call PlaneRANSAC::SolveMaster then, you will get the best plane according to your input.

Author
MIP
Examples:
ExampleRANSACPlane.cpp.

Definition at line 64 of file ExampleRANSACPlane.hh.

Constructor & Destructor Documentation

BIAS::PlaneRANSAC::PlaneRANSAC ( )

Definition at line 139 of file ExampleRANSACPlane.hh.

BIAS::PlaneRANSAC::~PlaneRANSAC ( )

Definition at line 142 of file ExampleRANSACPlane.hh.

Member Function Documentation

void BIAS::Debug::AddDebugLevel ( const long int  lv)
inlineinherited
void BIAS::Debug::AddDebugLevel ( const std::string &  name)
inlineinherited

Definition at line 362 of file Debug.hh.

static int BIAS::RANSAC< HomgPlane3D >::ComputeSampleCount ( double  inlying_data_fraction,
double  desired_prob_good,
unsigned int  sample_size 
)
inlinestaticprotectedinherited
long BIAS::Debug::ConsumeNextFreeDebuglevel_ ( )
inlineprotectedinherited

returns the next available debuglevel

Author
woelk 09/2006

Definition at line 521 of file Debug.hh.

bool BIAS::Debug::DebugLevelIsSet ( const long int  lv) const
inlineinherited
bool BIAS::Debug::DebugLevelIsSet ( const std::string &  name) const
inlineinherited

Definition at line 350 of file Debug.hh.

bool BIAS::PlaneRANSAC::EvaluateSolution ( const HomgPlane3D solution,
bool  existing_solution_flag,
std::vector< bool > &  inlier,
int &  accept_count,
double &  evaluate_score,
bool &  ok_to_terminate_flag 
)
virtual

The solution denoted by solution needs to be ranked.

This is done based on the number of inliers found for this solution and based on the accuracy reached on these inliers. So some kind of measurement is needed. Here it is the absolute distance between the homogeneous 3D points and the plane. If such a distance is below the threshold, and inlier has been found. The average distance over all inliers is the evaluate_score. While the number of inliers is entered in accept_count. For more details refer to documentation of this method in RANSAC.hh.

Reimplemented from BIAS::RANSAC< HomgPlane3D >.

Definition at line 174 of file ExampleRANSACPlane.hh.

References _dExpectedInlierFraction, _dInlierDistanceThreshold, _dSolutionErrorThreshold, BIAS::RANSAC< HomgPlane3D >::_uiDataSize, _vData, and BIAS::HomgPlane3D::DistanceSquared().

virtual bool BIAS::RANSAC< HomgPlane3D >::GenerateSamples ( int  sample_index,
std::vector< unsigned int > &  which_samples 
)
inlinevirtualinherited

pick a set of samples

Override this to specialize the technique used to generate samples. By default, random sampling is assumed but implementations may wish to use the latin-square sampling provided by generate_sample_evenspace (below), or some other problem-specific sampling strategy.

bool BIAS::RANSAC< HomgPlane3D >::GenerateSamplesEvenspace ( int  sample_index,
std::vector< unsigned int > &  sample_table 
)
inlineinherited
bool BIAS::RANSAC< HomgPlane3D >::GenerateSamplesRandom ( int  sample_index,
std::vector< unsigned int > &  sampletable 
)
inlineinherited
int BIAS::Debug::GetDebugLevel ( ) const
inlineinherited
std::ostream& BIAS::Debug::GetDebugStream ( ) const
inlineinherited

Definition at line 405 of file Debug.hh.

void BIAS::Debug::GetDebugStream ( std::ostream &  os) const
inlineinherited

Definition at line 414 of file Debug.hh.

double BIAS::RANSAC< HomgPlane3D >::GetFinalScore ( ) const
inlineinherited

Definition at line 260 of file RANSAC.hh.

static long int BIAS::Debug::GetGlobalDebugLevel ( )
inlinestaticinherited

Definition at line 431 of file Debug.hh.

int BIAS::PlaneRANSAC::GetSampleSolutions ( std::vector< unsigned int > &  which_samples,
std::vector< HomgPlane3D > &  solutions 
)
virtual

takes sample and computes solution for this sample.

This is usually done in an easy way, e.g. linearly. Sometimes solutions based on a minimum sample size are not unambiguous as for example in case of the 7 point algorithm for essential matrix estimation. In those cases all possible solutions have to be returned in the solutions vector.

Reimplemented from BIAS::RANSAC< HomgPlane3D >.

Definition at line 160 of file ExampleRANSACPlane.hh.

References _vData.

void BIAS::PlaneRANSAC::Init ( std::vector< HomgPoint3D > &  data,
double  inlier_distance_threshold,
bool  refine_solution,
double  expected_inlier_fraction,
double  solution_error_threshold 
)

Initializes RANSAC.

After calling the base RANSAC::Init method, the other parameters are set.

Attention
RANSAC::Init resets a lot of parameters to default values, for example explicitSampleCount. So setting these values before calling Init will have no effect.
Examples:
ExampleRANSACPlane.cpp.

Definition at line 145 of file ExampleRANSACPlane.hh.

References _dExpectedInlierFraction, _dInlierDistanceThreshold, _dSolutionErrorThreshold, BIAS::RANSAC< HomgPlane3D >::_uiDataSize, _vData, and BIAS::RANSAC< SolutionType >::Init().

void BIAS::RANSAC< HomgPlane3D >::Init ( unsigned int  sample_size,
unsigned int  max_solutions_per_sample = 1,
bool  refine_solution = false,
bool  greedy = false 
)
inlineinherited
long int BIAS::Debug::Name2DebugLevel ( const std::string &  name) const
inlineinherited

looks up a debuglevel in the internal map, returns 0 if not found

Author
woelk 09/2006

Definition at line 454 of file Debug.hh.

long int BIAS::Debug::NewDebugLevel ( const std::string &  name)
inlineinherited
void BIAS::Debug::PrintDebugLevel ( std::ostream &  os = std::cout) const
inlineinherited

Definition at line 383 of file Debug.hh.

bool BIAS::PlaneRANSAC::RefineSolution ( std::vector< unsigned int > &  which_samples,
HomgPlane3D solution,
std::vector< bool > &  new_inliers 
)
virtual

RefineSolution is only called, if the RefineSolutionFlag is set to true.

In any case, it is only applied to solutions, that have been found to be good, indicated by the return value of EvaluateSolution.

Reimplemented from BIAS::RANSAC< HomgPlane3D >.

Definition at line 218 of file ExampleRANSACPlane.hh.

References _vData, BIAS::SVD::GetNullvector(), BIAS::SVD::Rank(), and BIAS::Matrix< T >::Transpose().

void BIAS::Debug::RemoveDebugLevel ( const long int  lv)
inlineinherited

Definition at line 369 of file Debug.hh.

void BIAS::Debug::RemoveDebugLevel ( const std::string &  name)
inlineinherited

Definition at line 376 of file Debug.hh.

void BIAS::Debug::SetDebugLevel ( const long int  lv)
inlineinherited
void BIAS::Debug::SetDebugLevel ( const std::string &  name)
inlineinherited

Definition at line 325 of file Debug.hh.

void BIAS::Debug::SetDebugStream ( const std::ostream &  os)
inlineinherited

Definition at line 398 of file Debug.hh.

static void BIAS::Debug::SetGlobalDebugLevel ( long int  lev)
inlinestaticinherited

Definition at line 424 of file Debug.hh.

void BIAS::RANSAC< HomgPlane3D >::SetMaxSamples ( unsigned int  max_samples)
inlineinherited

Explicitly set max number of samples.

Ransacing will stop after max_samples samples, regardless of solution quality. Normally, more than a few thousand samples signifies a problem.

Definition at line 112 of file RANSAC.hh.

void BIAS::RANSAC< HomgPlane3D >::SetSampleCount ( unsigned int  uiSamples)
inlineinherited

Explicitly set number of samples.

Explicitly set number of samples to make in SolveMaster, i.e. Value of ComputeSampleCount() is ignored if this function is called with a strictly positive value uiSamples. Note: SolveMaster performs at most min(_uiMaxSamples, uiSamples) iterations

Author
koeser

Definition at line 124 of file RANSAC.hh.

void BIAS::Debug::ShowDebugLevel ( std::ostream &  os = std::cout) const
inlineinherited

prints all internally known debuglevels

Author
woelk 09/2006

Definition at line 496 of file Debug.hh.

virtual int BIAS::RANSAC< HomgPlane3D >::SolveMaster ( double  inlying_data_fraction,
HomgPlane3D solution,
std::vector< bool > &  inliers 
)
inlinevirtualinherited

Main computation function called by user.

This function is called to run the computation. On output, solution is set to the best solution found and inliers indicate which data were inliers to that solution. The inlying_data_fraction is responsible for the maximal number of sample sets taken from the data. The smaller the inlying_data_fraction, the more sample sets are taken

Attention
Do NOT override this function in derived classes, unless you want to do modifications in the RANSAC algorithm itself (and usually you dont want to do this ...) input : inlying_data_fraction expected inlier fraction output: solution solution inliers inlier flags
Returns
<0 indicates an error, otherwise number of chosen sample
Author
frahm, woelk
Examples:
ExampleRANSACPlane.cpp.

Member Data Documentation

bool BIAS::RANSAC< HomgPlane3D >::_bRefineSolution
protectedinherited

do we want to refine a good sample (one for which evaluate solution returned true)?

Definition at line 273 of file RANSAC.hh.

double BIAS::RANSAC< HomgPlane3D >::_dBestInlierEvaluateScore
protectedinherited

Definition at line 282 of file RANSAC.hh.

double BIAS::RANSAC< HomgPlane3D >::_dBestSampleEvaluateScore
protectedinherited

Definition at line 277 of file RANSAC.hh.

double BIAS::PlaneRANSAC::_dExpectedInlierFraction
protected

if a sample yields more than _dExpectedInlierFraction inliers and evaluate_score is lower than _dSolutionErrorThreshold, RANSAC will stop

Definition at line 132 of file ExampleRANSACPlane.hh.

Referenced by EvaluateSolution(), and Init().

double BIAS::PlaneRANSAC::_dInlierDistanceThreshold
protected

3D points with max distance _dInlierDistanceThreshold to plane are considered as inliers

Definition at line 128 of file ExampleRANSACPlane.hh.

Referenced by EvaluateSolution(), and Init().

double BIAS::RANSAC< HomgPlane3D >::_dLastBestSampleEvaluateScore
protectedinherited

Definition at line 278 of file RANSAC.hh.

double BIAS::RANSAC< HomgPlane3D >::_dProbabilityOfGoodSolution
protectedinherited

prob. for computing number of samples, set close to 1

Definition at line 291 of file RANSAC.hh.

double BIAS::PlaneRANSAC::_dSolutionErrorThreshold
protected

if a sample yields more than _dExpectedInlierFraction inliers and evaluate_score is lower than _dSolutionErrorThreshold, RANSAC will stop

Definition at line 136 of file ExampleRANSACPlane.hh.

Referenced by EvaluateSolution(), and Init().

double BIAS::RANSAC< HomgPlane3D >::_dSoSmallSolutionChange
protectedinherited

If all other conditions are right, and the fractional change in the solution statistics is less than this, stop sampling.

Definition at line 295 of file RANSAC.hh.

bool BIAS::RANSAC< HomgPlane3D >::_got_solution_flag
protectedinherited

if we already have a solution for which EvaluateSolution returned true

Definition at line 298 of file RANSAC.hh.

bool BIAS::RANSAC< HomgPlane3D >::_greedy
protectedinherited

if true, the first acceptable solution is returned

Definition at line 301 of file RANSAC.hh.

int BIAS::RANSAC< HomgPlane3D >::_iBestInlierAcceptCount
protectedinherited

refined best values

Definition at line 281 of file RANSAC.hh.

int BIAS::RANSAC< HomgPlane3D >::_iBestSampleAcceptCount
protectedinherited

sampled best values

Definition at line 276 of file RANSAC.hh.

long int BIAS::Debug::_liDebugLevel
protectedinherited

Definition at line 510 of file Debug.hh.

Referenced by BIAS::Debug::operator=(), and BIAS::ImageBase::operator=().

long int BIAS::Debug::_liNextDebugLevel
protectedinherited

new concept, debuglevel are managed here in the debug class

Definition at line 516 of file Debug.hh.

Referenced by BIAS::Debug::operator=().

std::map<std::string, long int> BIAS::Debug::_String2Debuglevel
protectedinherited

Definition at line 517 of file Debug.hh.

Referenced by BIAS::Debug::operator=().

unsigned BIAS::RANSAC< HomgPlane3D >::_uiDataSize
protectedinherited

number of data elements needed to compute a solution

Definition at line 270 of file RANSAC.hh.

Referenced by EvaluateSolution(), and Init().

unsigned int BIAS::RANSAC< HomgPlane3D >::_uiExplicitSampleNo
protectedinherited

use this number of samples

Definition at line 288 of file RANSAC.hh.

unsigned int BIAS::RANSAC< HomgPlane3D >::_uiMaxSamples
protectedinherited

absolute max number of samples

Definition at line 285 of file RANSAC.hh.

unsigned BIAS::RANSAC< HomgPlane3D >::_uiMaxSolutionsPerSample
protectedinherited

max number of solutions that are to be computed for one sample set

Definition at line 267 of file RANSAC.hh.

unsigned BIAS::RANSAC< HomgPlane3D >::_uiSampleSize
protectedinherited

number of samples available

Definition at line 264 of file RANSAC.hh.

std::vector<HomgPoint3D> BIAS::PlaneRANSAC::_vData
protected

input 3D points to fit 3D plane to

Definition at line 124 of file ExampleRANSACPlane.hh.

Referenced by EvaluateSolution(), GetSampleSolutions(), Init(), and RefineSolution().

std::ostream BIAS::Debug::_zDebugStream
staticprotectedinherited

Definition at line 511 of file Debug.hh.

Referenced by BIAS::Debug::operator=().

long int BIAS::Debug::GlobalDebugLevel = 0
staticprotectedinherited

Definition at line 513 of file Debug.hh.


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