MRPT  2.0.2
ransac.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #pragma once
10 
13 #include <functional>
14 #include <set>
15 
16 namespace mrpt::math
17 {
18 /** @addtogroup ransac_grp RANSAC and other model fitting algorithms
19  * \ingroup mrpt_math_grp
20  * @{ */
21 
22 /** Define overloaded functions for user types as required.
23  * This default implementation assumes datasets in matrices, with each sample
24  * being a column, the dimensionality being the number of rows. */
25 template <typename T>
26 size_t ransacDatasetSize(const CMatrixDynamic<T>& dataset)
27 {
28  return dataset.cols();
29 }
30 
31 /** A generic RANSAC implementation. By default, the input "dataset" and output
32  * "model" are matrices, but this can be changed via template arguments to be
33  * any user-defined type. Define ransacDatasetSize() for your custom data types.
34  *
35  * See \a RANSAC_Template::execute for more info on usage, and examples under
36  * `[MRPT]/samples/math_ransac_*`.
37  *
38  * \sa mrpt::math::ModelSearch, another RANSAC implementation where
39  * models can be anything else, not only matrices, and capable of genetic
40  * algorithms.
41  *
42  * \note New in MRPT 2.0.2: The second and third template arguments.
43  */
44 template <
45  typename NUMTYPE = double, typename DATASET = CMatrixDynamic<NUMTYPE>,
46  typename MODEL = CMatrixDynamic<NUMTYPE>>
48 {
49  public:
50  RANSAC_Template() : mrpt::system::COutputLogger("RANSAC_Template") {}
51 
52  /** The type of the function passed to mrpt::math::ransac - See the
53  * documentation for that method for more info. */
54  using TRansacFitFunctor = std::function<void(
55  const DATASET& allData, const std::vector<size_t>& useIndices,
56  std::vector<MODEL>& fitModels)>;
57 
58  /** The type of the function passed to mrpt::math::ransac - See the
59  * documentation for that method for more info. */
60  using TRansacDistanceFunctor = std::function<void(
61  const DATASET& allData, const std::vector<MODEL>& testModels,
62  const NUMTYPE distanceThreshold, unsigned int& out_bestModelIndex,
63  std::vector<size_t>& out_inlierIndices)>;
64 
65  /** The type of the function passed to mrpt::math::ransac - See the
66  * documentation for that method for more info. */
67  using TRansacDegenerateFunctor = std::function<bool(
68  const DATASET& allData, const std::vector<size_t>& useIndices)>;
69 
70  /** An implementation of the RANSAC algorithm for robust fitting of models
71  * to data.
72  *
73  * \param data A DxN matrix with all the observed data. D is the
74  * dimensionality of data points and N the number of points.
75  * \param
76  *
77  * This implementation is highly inspired on Peter Kovesi's MATLAB scripts
78  * (http://www.csse.uwa.edu.au/~pk).
79  * \return false if no good solution can be found, true on success.
80  * \note [MRPT 1.5.0] `verbose` parameter has been removed, supersedded by
81  * COutputLogger settings.
82  */
83  bool execute(
84  const DATASET& data, const TRansacFitFunctor& fit_func,
85  const TRansacDistanceFunctor& dist_func,
86  const TRansacDegenerateFunctor& degen_func,
87  const double distanceThreshold,
88  const unsigned int minimumSizeSamplesToFit,
89  std::vector<size_t>& out_best_inliers, MODEL& out_best_model,
90  const double prob_good_sample = 0.999,
91  const size_t maxIter = 2000) const;
92 
93 }; // end class
94 
95 /** The default instance of RANSAC, for double type */
97 
98 /** @} */
99 
100 } // namespace mrpt::math
101 
102 #include "ransac_impl.h"
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...
Definition: ransac.h:63
size_t ransacDatasetSize(const CMatrixDynamic< T > &dataset)
Define overloaded functions for user types as required.
Definition: ransac.h:26
This base provides a set of functions for maths stuff.
Versatile class for consistent logging and management of output messages.
size_type cols() const
Number of columns in the matrix.
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...
Definition: ransac.h:56
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
COutputLogger()
Default class constructor.
bool execute(const DATASET &data, const TRansacFitFunctor &fit_func, const TRansacDistanceFunctor &dist_func, const TRansacDegenerateFunctor &degen_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.
Definition: ransac_impl.h:21
A generic RANSAC implementation.
Definition: ransac.h:47
This template class provides the basic functionality for a general 2D any-size, resizable container o...
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...
Definition: ransac.h:68
static struct FontData data
Definition: gltext.cpp:144



Page generated by Doxygen 1.8.14 for MRPT 2.0.2 Git: 9b4fd2465 Mon May 4 16:59:08 2020 +0200 at lun may 4 17:26:07 CEST 2020