49 #include <visp3/core/vpHomogeneousMatrix.h>
50 #include <visp3/core/vpPoint.h>
51 #include <visp3/core/vpRGBa.h>
52 #include <visp3/vision/vpHomography.h>
53 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
54 #include <visp3/core/vpList.h>
56 #include <visp3/core/vpThread.h>
61 #ifdef VISP_HAVE_CPP11_COMPATIBILITY
103 PREFILTER_DEGENERATE_POINTS,
104 CHECK_DEGENERATE_POINTS
108 std::list<vpPoint> listP;
119 std::vector<vpPoint> c3d;
121 bool computeCovariance;
126 unsigned int ransacNbInlierConsensus;
130 std::vector<vpPoint> ransacInliers;
132 std::vector<unsigned int> ransacInlierIndex;
134 double ransacThreshold;
137 double distanceToPlaneForCoplanarityTest;
142 std::vector<vpPoint> listOfPoints;
144 bool useParallelRansac;
146 int nbParallelRansacThreads;
155 RansacFunctor(
const vpHomogeneousMatrix &cMo_,
const unsigned int ransacNbInlierConsensus_,
156 const int ransacMaxTrials_,
const double ransacThreshold_,
const unsigned int initial_seed_,
157 const bool checkDegeneratePoints_,
const std::vector<vpPoint> &listOfUniquePoints_,
159 #ifdef VISP_HAVE_CPP11_COMPATIBILITY
160 , std::atomic<bool> &abort
164 #ifdef VISP_HAVE_CPP11_COMPATIBILITY
167 m_best_consensus(), m_checkDegeneratePoints(checkDegeneratePoints_), m_cMo(cMo_), m_foundSolution(
false),
168 m_func(func_), m_initial_seed(initial_seed_), m_listOfUniquePoints(listOfUniquePoints_), m_nbInliers(0),
169 m_ransacMaxTrials(ransacMaxTrials_), m_ransacNbInlierConsensus(ransacNbInlierConsensus_),
170 m_ransacThreshold(ransacThreshold_)
172 #if (defined(_WIN32) && (defined(_MSC_VER) || defined(__MINGW32__)) || defined(ANDROID))
177 void operator()() { m_foundSolution = poseRansacImpl(); }
180 bool getResult()
const {
return m_foundSolution; }
182 std::vector<unsigned int> getBestConsensus()
const {
return m_best_consensus; }
186 unsigned int getNbInliers()
const {
return m_nbInliers; }
189 #ifdef VISP_HAVE_CPP11_COMPATIBILITY
190 std::atomic<bool> &m_abort;
192 std::vector<unsigned int> m_best_consensus;
193 bool m_checkDegeneratePoints;
195 bool m_foundSolution;
197 unsigned int m_initial_seed;
198 std::vector<vpPoint> m_listOfUniquePoints;
199 unsigned int m_nbInliers;
200 int m_ransacMaxTrials;
201 unsigned int m_ransacNbInlierConsensus;
202 double m_ransacThreshold;
204 bool poseRansacImpl();
216 void addPoint(
const vpPoint &P);
217 void addPoints(
const std::vector<vpPoint> &lP);
222 bool coplanar(
int &coplanar_plane_type);
235 void setDistanceToPlaneForCoplanarityTest(
double d);
236 void setLambda(
double a) { lambda = a; }
237 void setVvsEpsilon(
const double eps)
245 void setVvsIterMax(
int nb) { vvsIterMax = nb; }
247 void setRansacNbInliersToReachConsensus(
const unsigned int &nbC) { ransacNbInlierConsensus = nbC; }
248 void setRansacThreshold(
const double &t)
251 if (t > std::numeric_limits<double>::epsilon()) {
257 void setRansacMaxTrials(
const int &rM) { ransacMaxTrials = rM; }
258 unsigned int getRansacNbInliers()
const {
return (
unsigned int)ransacInliers.size(); }
259 std::vector<unsigned int> getRansacInlierIndex()
const {
return ransacInlierIndex; }
260 std::vector<vpPoint> getRansacInliers()
const {
return ransacInliers; }
268 void setCovarianceComputation(
const bool &flag) { computeCovariance = flag; }
279 vpMatrix getCovarianceMatrix()
const
281 if (!computeCovariance)
282 vpTRACE(
"Warning : The covariance matrix has not been computed. See "
283 "setCovarianceComputation() to do it.");
285 return covarianceMatrix;
299 inline void setRansacFilterFlag(
const RANSAC_FILTER_FLAGS &flag) { ransacFlag = flag; }
306 inline int getNbParallelRansacThreads()
const {
return nbParallelRansacThreads; }
316 inline void setNbParallelRansacThreads(
const int nb) { nbParallelRansacThreads = nb; }
323 inline bool getUseParallelRansac()
const {
return useParallelRansac; }
330 inline void setUseParallelRansac(
const bool use) { useParallelRansac = use; }
337 std::vector<vpPoint> getPoints()
const
339 std::vector<vpPoint> vectorOfPoints(listP.begin(), listP.end());
340 return vectorOfPoints;
350 static int computeRansacIterations(
double probability,
double epsilon,
const int sampleSize = 4,
351 int maxIterations = 2000);
353 static void findMatch(std::vector<vpPoint> &p2D, std::vector<vpPoint> &p3D,
354 const unsigned int &numberOfInlierToReachAConsensus,
const double &threshold,
356 const int &maxNbTrials=10000,
const bool useParallelRansac=
true,
const unsigned int nthreads=0,