49 #include <visp3/core/vpColVector.h> 50 #include <visp3/core/vpDebug.h> 51 #include <visp3/core/vpMath.h> 52 #include <visp3/core/vpUniRand.h> 72 template <
class vpTransformation>
class vpRansac 76 vpColVector &inliers,
int consensus = 1000,
double not_used = 0.0,
77 const int maxNbumbersOfTrials = 10000);
110 template <
class vpTransformation>
112 vpColVector &inliers,
int consensus,
double not_used,
113 const int maxNbumbersOfTrials)
123 int maxTrials = maxNbumbersOfTrials;
124 int maxDataTrials = 1000;
131 bool solutionFind =
false;
137 vpUniRand random((
const long)time(NULL));
139 unsigned int *ind =
new unsigned int[s];
142 double residual = 0.0;
143 while ((N > trialcount) && (consensus > bestscore)) {
148 bool degenerate =
true;
151 while (degenerate ==
true) {
153 for (
unsigned int i = 0; i < s; i++)
154 ind[i] = (
unsigned int)ceil(random() * npts) - 1;
157 degenerate = vpTransformation::degenerateConfiguration(x, ind);
163 if (count > maxDataTrials) {
171 vpTransformation::computeTransformation(x, ind, M);
175 vpTransformation::computeResidual(x, M, d);
180 for (
unsigned int i = 0; i < npts; i++) {
181 double resid = fabs(d[i]);
185 residual += fabs(d[i]);
190 if (ninliers > bestscore)
192 bestscore = ninliers;
193 bestinliers = inliers;
200 double fracinliers = (double)ninliers / (
double)npts;
202 double pNoOutliers = 1 - pow(fracinliers, static_cast<int>(s));
206 N = (log(1 - p) / log(pNoOutliers));
209 trialcount = trialcount + 1;
211 if (trialcount > maxTrials) {
212 vpTRACE(
"ransac reached the maximum number of %d trials", maxTrials);
218 if (solutionFind ==
true)
221 inliers = bestinliers;
223 vpTRACE(
"ransac was unable to find a useful solution");
228 residual /= ninliers;
error that can be emited by ViSP classes.
static Type maximum(const Type &a, const Type &b)
static Type minimum(const Type &a, const Type &b)
Implementation of column vector and the associated operations.
static bool ransac(unsigned int npts, vpColVector &x, unsigned int s, double t, vpColVector &model, vpColVector &inliers, int consensus=1000, double not_used=0.0, const int maxNbumbersOfTrials=10000)
RANSAC - Robustly fits a model to data with the RANSAC algorithm.
This class is a generic implementation of the Ransac algorithm. It cannot be used alone...
Class for generating random numbers with uniform probability density.