24 template <
typename NUMTYPE>
29 const unsigned int minimumSizeSamplesToFit,
32 const size_t maxIter)
const 36 ASSERT_(minimumSizeSamplesToFit >= 1)
46 const size_t maxDataTrials =
49 out_best_model.setSize(
51 out_best_inliers.clear();
53 size_t trialcount = 0;
54 size_t bestscore = std::string::npos;
59 while (N > trialcount)
64 bool degenerate =
true;
66 std::vector<CMatrixTemplateNumeric<NUMTYPE>> MODELS;
71 ind.resize(minimumSizeSamplesToFit);
78 degenerate = degen_func(
data, ind);
84 fit_func(
data, ind, MODELS);
90 degenerate = MODELS.empty();
94 if (++
count > maxDataTrials)
107 unsigned int bestModelIdx = 1000;
112 data, MODELS, NUMTYPE(distanceThreshold), bestModelIdx,
114 ASSERT_(bestModelIdx < MODELS.size());
118 const size_t ninliers = inliers.size();
119 bool update_estim_num_iters =
124 if (ninliers > bestscore ||
125 (bestscore == std::string::npos && ninliers != 0))
127 bestscore = ninliers;
129 out_best_model = MODELS[bestModelIdx];
130 out_best_inliers = inliers;
131 update_estim_num_iters =
true;
134 if (update_estim_num_iters)
138 double fracinliers = ninliers /
static_cast<double>(Npts);
141 pow(fracinliers, static_cast<double>(minimumSizeSamplesToFit));
143 pNoOutliers = std::max(
144 std::numeric_limits<double>::epsilon(),
147 1.0 - std::numeric_limits<double>::epsilon(),
150 N =
static_cast<size_t>(log(1 -
p) / log(pNoOutliers));
153 "Iter #%u Estimated number of iters: %u pNoOutliers = %f " 155 (
unsigned)trialcount, (
unsigned)N, pNoOutliers,
156 (
unsigned)ninliers));
163 "trial %u out of %u \r", (
unsigned int)trialcount,
164 (
unsigned int)ceil(static_cast<double>(N))));
167 if (trialcount > maxIter)
171 "Warning: maximum number of trials (%u) reached\n",
177 if (
size(out_best_model, 1) > 0)
180 format(
"Finished in %u iterations.\n", (
unsigned)trialcount));
196 #ifdef HAVE_LONG_DOUBLE A namespace of pseudo-random numbers genrators of diferent distributions.
GLuint GLuint GLsizei count
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
std::function< bool(const CMatrixTemplateNumeric< NUMTYPE > &allData, const mrpt::vector_size_t &useIndices)> TRansacDegenerateFunctor
The type of the function passed to mrpt::math::ransac - See the documentation for that method for mor...
This base provides a set of functions for maths stuff.
#define MRPT_LOG_WARN(_STRING)
#define MRPT_LOG_INFO(_STRING)
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
#define MRPT_LOG_DEBUG(_STRING)
std::function< void(const CMatrixTemplateNumeric< NUMTYPE > &allData, const mrpt::vector_size_t &useIndices, std::vector< CMatrixTemplateNumeric< NUMTYPE > > &fitModels)> TRansacFitFunctor
The type of the function passed to mrpt::math::ransac - See the documentation for that method for mor...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
std::function< void(const CMatrixTemplateNumeric< NUMTYPE > &allData, const std::vector< CMatrixTemplateNumeric< NUMTYPE > > &testModels, const NUMTYPE distanceThreshold, unsigned int &out_bestModelIndex, mrpt::vector_size_t &out_inlierIndices)> TRansacDistanceFunctor
The type of the function passed to mrpt::math::ransac - See the documentation for that method for mor...
A matrix of dynamic size.
std::vector< size_t > vector_size_t
A generic RANSAC implementation with models as matrices.
CRandomGenerator & getRandomGenerator()
A static instance of a CRandomGenerator class, for use in single-thread applications.
void drawUniformVector(VEC &v, const double unif_min=0, const double unif_max=1)
Fills the given vector with independent, uniformly distributed samples.
GLsizei GLsizei GLenum GLenum const GLvoid * data
std::vector< size_t > vector_size_t