20 template <
typename NUMTYPE, 
typename DATASET, 
typename MODEL>
    25     const unsigned int minimumSizeSamplesToFit,
    26     std::vector<size_t>& out_best_inliers, MODEL& out_best_model,
    27     const double p, 
const size_t maxIter)
 const    39     const size_t maxDataTrials = 100;
    42     out_best_model = MODEL();
    43     out_best_inliers.clear();
    45     size_t trialcount = 0;
    46     size_t bestscore = std::string::npos;  
    49     std::vector<size_t> ind(minimumSizeSamplesToFit);
    51     while (N > trialcount)
    56         bool degenerate = 
true;
    58         std::vector<MODEL> MODELS;
    63             ind.resize(minimumSizeSamplesToFit);
    68                 ind, 0.0, Npts - 1 + 0.999999);
    71             degenerate = degen_func(
data, ind);
    77                 fit_func(
data, ind, MODELS);
    83                 degenerate = MODELS.empty();
    87             if (++count > maxDataTrials)
   100         unsigned int bestModelIdx = std::numeric_limits<unsigned int>::max();
   101         std::vector<size_t> inliers;
   105                 data, MODELS, static_cast<NUMTYPE>(distanceThreshold),
   106                 bestModelIdx, inliers);
   111         const size_t ninliers = inliers.size();
   114         bool update_estim_num_iters = (trialcount == 0);
   116         if (ninliers > bestscore ||
   117             (bestscore == std::string::npos && ninliers != 0))
   119             bestscore = ninliers;  
   121             out_best_model = std::move(MODELS[bestModelIdx]);
   122             out_best_inliers = std::move(inliers);
   123             update_estim_num_iters = 
true;
   126         if (update_estim_num_iters)
   130             double fracinliers = ninliers / 
static_cast<double>(Npts);
   133                 pow(fracinliers, static_cast<double>(minimumSizeSamplesToFit));
   135             pNoOutliers = std::max(
   136                 std::numeric_limits<double>::epsilon(),
   138             pNoOutliers = std::min(
   139                 1.0 - std::numeric_limits<double>::epsilon(),
   142             N = 
static_cast<size_t>(log(1 - p) / log(pNoOutliers));
   144                 "Iter #%u Estimated number of iters: %u  pNoOutliers = %f  "   146                 (
unsigned)trialcount, (
unsigned)N, pNoOutliers,
   153             "trial %u out of %u", (
unsigned int)trialcount,
   154             (
unsigned int)ceil(static_cast<double>(N)));
   157         if (trialcount > maxIter)
   160                 "Warning: maximum number of trials (%u) reached\n",
   166     if (!out_best_inliers.empty())
 std::function< void(const DATASET &allData, const std::vector< MODEL > &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...
 
#define ASSERT_BELOW_(__A, __B)
 
size_t ransacDatasetSize(const CMatrixDynamic< T > &dataset)
Define overloaded functions for user types as required. 
 
#define MRPT_LOG_WARN_FMT(_FMT_STRING,...)
 
This base provides a set of functions for maths stuff. 
 
#define MRPT_LOG_DEBUG_FMT(_FMT_STRING,...)
Use: MRPT_LOG_DEBUG_FMT("i=%u", i); 
 
#define ASSERT_ABOVEEQ_(__A, __B)
 
std::function< void(const DATASET &allData, const std::vector< size_t > &useIndices, std::vector< MODEL > &fitModels)> TRansacFitFunctor
The type of the function passed to mrpt::math::ransac - See the documentation for that method for mor...
 
#define ASSERT_ABOVE_(__A, __B)
 
bool execute(const DATASET &data, const TRansacFitFunctor &fit_func, const TRansacDistanceFunctor &dist_func, const TRansacDegenerateFunctor °en_func, const double distanceThreshold, const unsigned int minimumSizeSamplesToFit, std::vector< size_t > &out_best_inliers, MODEL &out_best_model, const double prob_good_sample=0.999, const size_t maxIter=2000) const
An implementation of the RANSAC algorithm for robust fitting of models to data. 
 
#define MRPT_LOG_WARN(_STRING)
 
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. 
 
#define MRPT_LOG_INFO_FMT(_FMT_STRING,...)
 
std::function< bool(const DATASET &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...
 
static struct FontData data