Find Matches using Ransac.
#include <visp3/core/vpHomogeneousMatrix.h>
#include <visp3/core/vpMath.h>
#include <visp3/core/vpPoint.h>
#include <visp3/vision/vpPose.h>
#include <stdio.h>
#include <stdlib.h>
#define L 0.1
int main()
{
#ifdef ENABLE_VISP_NAMESPACE
#endif
#if (defined(VISP_HAVE_LAPACK) || defined(VISP_HAVE_EIGEN3) || defined(VISP_HAVE_OPENCV))
try {
std::cout << "Find Matches using Ransac" << std::endl;
std::vector<vpPoint> P;
P.push_back(
vpPoint(-0, L / 2., L));
std::vector<vpPoint> p(P.size());
for (unsigned int i = 0; i < P.size(); i++) {
}
unsigned int ninliers;
std::vector<vpPoint> inliers;
double threshold = 1e-6;
unsigned int nbInlierToReachConsensus = (unsigned int)(P.size());
vpPose::findMatch(p, P, nbInlierToReachConsensus, threshold, ninliers, inliers, cMo);
std::cout << "Inliers: " << std::endl;
for (unsigned int i = 0; i < inliers.size(); i++) {
inliers[i].print();
std::cout << std::endl;
}
std::cout <<
"cMo :\n" <<
vpPoseVector(cMo).
t() << std::endl << std::endl;
std::cout << std::endl;
std::cout <<
"reference cMo :\n" << pose_ref.
t() << std::endl << std::endl;
std::cout <<
"estimated cMo :\n" << pose_est.
t() << std::endl << std::endl;
int test_fail = 0;
for (unsigned int i = 0; i < 6; i++) {
if (std::fabs(pose_ref[i] - pose_est[i]) > 0.001)
test_fail = 1;
}
std::cout << "Matching is " << (test_fail ? "badly" : "well") << " performed" << std::endl;
return (test_fail ? EXIT_FAILURE : EXIT_SUCCESS);
}
std::cout << "Catch an exception: " << e << std::endl;
return EXIT_FAILURE;
}
#else
std::cout << "Cannot run this example: install Lapack, Eigen3 or OpenCV" << std::endl;
return EXIT_SUCCESS;
#endif
}
error that can be emitted by ViSP classes.
Implementation of an homogeneous matrix and operations on such kind of matrices.
static double rad(double deg)
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
double get_y() const
Get the point y coordinate in the image plane.
double get_x() const
Get the point x coordinate in the image plane.
Implementation of a pose vector and operations on poses.
static void findMatch(std::vector< vpPoint > &p2D, std::vector< vpPoint > &p3D, const unsigned int &numberOfInlierToReachAConsensus, const double &threshold, unsigned int &ninliers, std::vector< vpPoint > &listInliers, vpHomogeneousMatrix &cMo, const int &maxNbTrials=10000, bool useParallelRansac=true, unsigned int nthreads=0, FuncCheckValidityPose func=nullptr)