60 #include <visp/vpMath.h>
61 #include <visp/vpRotationMatrix.h>
62 #include <visp/vpHomography.h>
63 #include <visp/vpDebug.h>
64 #include <visp/vpThetaUVector.h>
66 #include <visp/vpPoint.h>
67 #include <visp/vpMath.h>
68 #include <visp/vpHomogeneousMatrix.h>
69 #include <visp/vpDebug.h>
71 #include <visp/vpRansac.h>
72 #include <visp/vpParseArgv.h>
75 #define GETOPTARGS "h"
77 void usage(
const char *name,
const char *badparam);
78 bool getOptions(
int argc,
const char **argv);
88 void usage(
const char *name,
const char *badparam)
91 Test the Ransac homography estimation algorithm.\n\
102 fprintf(stderr,
"ERROR: \n" );
103 fprintf(stderr,
"\nBad parameter [%s]\n", badparam);
116 bool getOptions(
int argc,
const char **argv)
123 case 'h': usage(argv[0], NULL);
return false;
break;
126 usage(argv[0], optarg_);
131 if ((c == 1) || (c == -1)) {
133 usage(argv[0], NULL);
134 std::cerr <<
"ERROR: " << std::endl;
135 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
144 main(
int argc,
const char ** argv)
148 if (getOptions(argc, argv) ==
false) {
153 unsigned int nbpt = 11;
155 std::vector<vpPoint> P(nbpt);
156 std::vector<double> xa(nbpt), ya(nbpt), xb(nbpt), yb(nbpt);
158 std::vector<vpPoint> aP(nbpt);
159 std::vector<vpPoint> bP(nbpt);
161 P[0].setWorldCoordinates(-L,-L, 0 ) ;
162 P[1].setWorldCoordinates(2*L,-L, 0 ) ;
163 P[2].setWorldCoordinates(L,L, 0 ) ;
164 P[3].setWorldCoordinates(-L,3*L, 0 ) ;
165 P[4].setWorldCoordinates(0,0, L ) ;
166 P[5].setWorldCoordinates(L,-2*L, L ) ;
167 P[6].setWorldCoordinates(L,-4*L, 2*L ) ;
168 P[7].setWorldCoordinates(-2*L,-L, -3*L ) ;
169 P[8].setWorldCoordinates(-5*L,-5*L, 0 ) ;
170 P[9].setWorldCoordinates(-2*L,+3*L, 4*L ) ;
171 P[10].setWorldCoordinates(-2*L,-0.5*L, 0 ) ;
173 std::vector<bool> inliers_ground_truth(nbpt,
false);
174 inliers_ground_truth[0] =
true;
175 inliers_ground_truth[1] =
true;
176 inliers_ground_truth[2] =
true;
177 inliers_ground_truth[3] =
true;
178 inliers_ground_truth[8] =
true;
179 inliers_ground_truth[10] =
true;
184 for(
unsigned int i=0 ; i < nbpt ; i++)
188 xa[i] = P[i].get_x() ;
189 ya[i] = P[i].get_y() ;
192 for(
unsigned int i=0 ; i < nbpt ; i++)
196 xb[i] = P[i].get_x() ;
197 yb[i] = P[i].get_y() ;
199 std::cout <<
"-------------------------------" <<std::endl ;
204 std::cout <<
"Compare with built homography H = R + t/d n " << std::endl;
207 std::cout <<
"aHb built from the displacement: \n" << aHb_built/aHb_built[2][2] << std::endl ;
209 aHb_built.computeDisplacement(aRb, aTb, n) ;
210 std::cout <<
"Rotation aRb: " <<std::endl ;
211 std::cout << aRb << std::endl ;
212 std::cout <<
"Translation: aTb" <<std::endl;
213 std::cout << (aTb).t() <<std::endl ;
214 std::cout <<
"Normal to the plane: n" <<std::endl;
215 std::cout << (n).t() <<std::endl ;
217 std::cout <<
"-------------------------------" <<std::endl ;
219 std::vector<bool> inliers;
225 std::cout <<
"aHb estimated using ransac:\n" << aHb << std::endl ;
226 std::cout <<
"Inliers indexes (should be 0,1,2,3,8,10): ";
227 for (
unsigned int i=0; i< inliers.size(); i++)
228 if (inliers[i]) std::cout << i <<
",";
229 std::cout << std::endl;
231 if (inliers == inliers_ground_truth) {
232 std::cout <<
"Ransac estimation succeed" << std::endl;
236 std::cout <<
"Ransac estimation fails" << std::endl;
241 std::cout <<
"Catch an exception: " << e << std::endl;
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
error that can be emited by ViSP classes.
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
The vpRotationMatrix considers the particular case of a rotation matrix.
This class aims to compute the homography wrt.two images.
static bool ransac(const std::vector< double > &xb, const std::vector< double > &yb, const std::vector< double > &xa, const std::vector< double > &ya, vpHomography &aHb, std::vector< bool > &inliers, double &residual, unsigned int nbInliersConsensus, double threshold, bool normalization=true)
static double rad(double deg)
Class that provides a data structure for the column vectors as well as a set of operations on these v...
This class defines the container for a plane geometrical structure.
Class that consider the case of a translation vector.