Go to the documentation of this file.
23 template <
typename NUMTYPE>
28 const unsigned int minimumSizeSamplesToFit,
29 std::vector<size_t>& out_best_inliers,
31 const size_t maxIter)
const
35 ASSERT_(minimumSizeSamplesToFit >= 1);
38 const size_t D =
data.rows();
39 const size_t Npts =
data.cols();
44 const size_t maxDataTrials =
47 out_best_model.setSize(
49 out_best_inliers.clear();
51 size_t trialcount = 0;
52 size_t bestscore = std::string::npos;
55 std::vector<size_t> ind(minimumSizeSamplesToFit);
57 while (N > trialcount)
62 bool degenerate =
true;
64 std::vector<CMatrixTemplateNumeric<NUMTYPE>> MODELS;
69 ind.resize(minimumSizeSamplesToFit);
74 ind, 0.0, Npts - 1 + 0.999999);
77 degenerate = degen_func(
data, ind);
83 fit_func(
data, ind, MODELS);
89 degenerate = MODELS.empty();
93 if (++
count > maxDataTrials)
106 unsigned int bestModelIdx = 1000;
107 std::vector<size_t> inliers;
111 data, MODELS, NUMTYPE(distanceThreshold), bestModelIdx,
113 ASSERT_(bestModelIdx < MODELS.size());
117 const size_t ninliers = inliers.size();
118 bool update_estim_num_iters =
123 if (ninliers > bestscore ||
124 (bestscore == std::string::npos && ninliers != 0))
126 bestscore = ninliers;
128 out_best_model = MODELS[bestModelIdx];
129 out_best_inliers = inliers;
130 update_estim_num_iters =
true;
133 if (update_estim_num_iters)
137 double fracinliers = ninliers /
static_cast<double>(Npts);
140 pow(fracinliers,
static_cast<double>(minimumSizeSamplesToFit));
142 pNoOutliers = std::max(
143 std::numeric_limits<double>::epsilon(),
146 1.0 - std::numeric_limits<double>::epsilon(),
149 N =
static_cast<size_t>(log(1 -
p) / log(pNoOutliers));
152 "Iter #%u Estimated number of iters: %u pNoOutliers = %f "
154 (
unsigned)trialcount, (
unsigned)N, pNoOutliers,
155 (
unsigned)ninliers));
162 "trial %u out of %u \r", (
unsigned int)trialcount,
163 (
unsigned int)ceil(
static_cast<double>(N))));
166 if (trialcount > maxIter)
170 "Warning: maximum number of trials (%u) reached\n",
176 if (out_best_model.rows() > 0)
179 format(
"Finished in %u iterations.\n", (
unsigned)trialcount));
195 #ifdef HAVE_LONG_DOUBLE
#define MRPT_LOG_INFO(_STRING)
#define MRPT_LOG_DEBUG(_STRING)
Use: MRPT_LOG_DEBUG("message");
std::function< void(const CMatrixTemplateNumeric< NUMTYPE > &allData, const std::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.
#define ASSERT_(f)
Defines an assertion mechanism.
A matrix of dynamic size.
GLsizei GLsizei GLenum GLenum const GLvoid * data
GLuint GLuint GLsizei count
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
std::function< bool(const CMatrixTemplateNumeric< NUMTYPE > &allData, const std::vector< size_t > &useIndices)> TRansacDegenerateFunctor
The type of the function passed to mrpt::math::ransac - See the documentation for that method for mor...
#define MRPT_LOG_WARN(_STRING)
CRandomGenerator & getRandomGenerator()
A static instance of a CRandomGenerator class, for use in single-thread applications.
std::function< void(const CMatrixTemplateNumeric< NUMTYPE > &allData, const std::vector< CMatrixTemplateNumeric< NUMTYPE > > &testModels, const NUMTYPE distanceThreshold, unsigned int &out_bestModelIndex, std::vector< size_t > &out_inlierIndices)> TRansacDistanceFunctor
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.
A generic RANSAC implementation with models as matrices.
A namespace of pseudo-random numbers generators of diferent distributions.
void drawUniformVector(VEC &v, const double unif_min=0, const double unif_max=1)
Fills the given vector with independent, uniformly distributed samples.
Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST | |